Audio library for FreeBasic - Features

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Audio library for FreeBasic - Features

Post by VANYA »

In general, I randomly obtained a normal result with such an entry in the file sequencer.bi:

Code: Select all

const MaxTracks=16

TYPE MidiSequence
	Tracks as long
	Divisions as long
	Tempo as longint ' or double
	Track(1 to MaxTracks) as string
END TYPE
Why is that? I don't know, but it works! You can check for yourself on the win32 system.

Please, who has win32, check whether it works correctly.

Unfortunately in DOS the sound I don't have very good, but the melody sounds similar, although of course it is better to check for someone who has an older computer.
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Audio library for FreeBasic - Features

Post by VANYA »

And by the way, I'll remind you of my question:
angros47! Your sequencer.bi file writed:

const MaxTracks=16

I am not an expert in MIDI, but one person who knows a little about it said that this is a limitation and maybe not all midi files will be able to play. This is true?
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

Try another thing, too:

Code: Select all

Tempo as unsigned integer
And see if it fixes the issue you are having (I indeed should have put that, since it's a 4 byte variable, and cannot be negative, according to the MIDI standard)
VANYA wrote: Oct 19, 2022 15:30 And by the way, I'll remind you of my question:
angros47! Your sequencer.bi file writed:

const MaxTracks=16

I am not an expert in MIDI, but one person who knows a little about it said that this is a limitation and maybe not all midi files will be able to play. This is true?
No, it is not true: MIDI can have at most 16 channels (it cannot have more, because each midi event is represented by a byte: the most significant 4 bits are the event, the least significant 4 are the channel number, and with 4 bits you cannot represent more than 16 numbers, so no more than 16 channels can be included without changing the MIDI format and breaking compatibility).

And MIDI files are usually of two formats (https://www.music.mcgill.ca/~ich/classe ... html#BM2_2): format 0 has only one track, that contains events of all channels, and format 1 has one track per channel (since channels cannot be more than 16, there cannot be more than 16 tracks). There is also a third format, called format 2, that allows to have different musics in the same MIDI file, but it's almost never used, and many trackers don't even support it.

So, MIDI files that are compliant to the supported formats will never have more than 16 tracks
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Audio library for FreeBasic - Features

Post by VANYA »

Tempo as unsigned integer
No, it doesn't work. Only variable 8 bytes for "Tempo". I can't explain it because I don't know the MIDI format or the device of your library at all. But this is a fact. Moreover, even on DOS, the sound more or less became similar to the original. But I can't say for sure, because a PCI card with adlib is not the best solution for testing.
No, it is not true: MIDI can have at most 16 channels
Thanks for the answer!
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

Replaced integer with longint, and reuploaded it on sourceforge. Try if it works now
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Audio library for FreeBasic - Features

Post by VANYA »

angros47 wrote: Oct 20, 2022 21:14 Replaced integer with longint, and reuploaded it on sourceforge. Try if it works now
You forgot about it:
angros47 wrote: ↑Oct 18, 2022 20:38
2)Have you tested it on many installations, or just one? The optimal pauses can change depending on the version of Alsa, on the CPU speed, and so on.

I only tested on one computer. But if it's so critical, why not add a delay parameter to the SoundmidiSet, for example?
And that's important! On linux, this is critical. Some will work with sleep(1), while others "PLAY" will stutter with sleep(1).
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

Before doing that change, I need more information:

1) does the issue affect only the music played with the PLAY command, or also midi files loaded and played?
2) What happens if you play a music in background with the PLAY command (using "MB as the beginning of the string)?

Because I am not sure if it is just depending on that delay, or if it's a symptom of a more serious bug.

By just replacing "SLEEP 1" with, let's say, "SLEEP 20" everything works fine?
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Audio library for FreeBasic - Features

Post by VANYA »

The problem of braking and music distortion only when loading and playing MIDI files (Please note this is for linux only)!
Changing sleep(1) -> sleep(15-20) solves this problem

When using the PLAY command directly with the string, I did not notice any problems (it does not matter when using MB or without it)

I also noticed an unpleasant hiss at the beginning of each music (0.2-2 seconds). It's as if the buffer is initially filled with garbage. It happens on linux.
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

You just changed the SLEEP command inside the file "playtomidi.bas"? Because that command should affect only the behavior of the PLAY command, and I don't understand how it could affect the midi sequencer
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Audio library for FreeBasic - Features

Post by VANYA »

@angros47

I do not understand. Now I tried with sleep(1) , but everything plays fine. And the garbage at the beginning at different launches, that is, then it is not there. Some black magic...
Sounds good on your version of Linux?
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

Usually yes. As I said, the issue is in the buffer size: a buffer size too small causes a buffer underrun, resulting in stuttering, a buffer too big causes longer latency, and wrong timing for the notes. The library tries to find the optimal buffer size for each system, and sometimes it needs some second to do it
hhr
Posts: 208
Joined: Nov 29, 2019 10:41

Re: Audio library for FreeBasic - Features

Post by hhr »

Can you tell me, which Linux distribution you use? And what you installed or made to play midi files with sfx?
I tried Debian and Lubuntu. Timidity and VLC with vlc-plugin fluidsynth can play mid files without problems.
But I have big problems with sfx and mid files in Linux.
Sfx cannot play onestop.mid from the Windows Media folder.
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Re: Audio library for FreeBasic - Features

Post by angros47 »

I use Ubuntu. Tested it in the past on Ubuntu 10, 12, 16, (32 bits) and 20 and 22 (64 bits)

No extra installation is required, to be able to play midi, but usually this will mean that the internal FM player will be used, so the MIDI feature will be pretty limited (the audio will resemble a bit the audio of an AdLib card, or the audio of Windows 3.1). You would get a better quality by installing also Timidity and an appropriate sound font.

Have you tried setting the tempo variable as longint, like VANYA suggested?
hhr
Posts: 208
Joined: Nov 29, 2019 10:41

Re: Audio library for FreeBasic - Features

Post by hhr »

I will try it tomorrow, thank you.
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Audio library for FreeBasic - Features

Post by VANYA »

hhr wrote: Oct 22, 2022 18:47 Sfx cannot play onestop.mid from the Windows Media folder.
This file the sfx won't be able to play because onestop.mid contains 17 tracks and sfx only has a buffer for 16 tracks:

Code: Select all

const MaxTracks=16
so segmentation fault due to small array size:

Code: Select all

Track(1 to MaxTracks) as string
Post Reply