Active Forums => Programs => Topic started by: SierraKen on October 31, 2019, 10:35:27 pm
Title: Sound Question
Post by: SierraKen on October 31, 2019, 10:35:27 pm
I'm 99% sure this is impossible in QB64, but is there a way to make a graphical display per ms of sound output? I'm talking about the same display some sound programs have like the old Winamp or others that show lines going up and down showing spikes of music volume and/or treble and bass output amounts. I looked into this deeply a few months ago but couldn't find this on the QB64.org Wiki page. I think all they have is the simple way to load, play, stop, FF, rewind, and pause. I started on a music player once that did these things but gave up because there's just so many better programs out there. I remember someone posting their sound player on my forum thread about it. I'm just wondering if there can be that graphical output. Thank you. I wonder if a PORT command would work somehow? Although I do use a USB sound card.
Title: Re: Sound Question
Post by: SMcNeill on October 31, 2019, 11:32:06 pm
Petr has worked several programs which do this. If you search the forums, you can probably find some nice examples of his stuff floating around a few of them.
Title: Re: Sound Question
Post by: SierraKen on November 01, 2019, 01:37:56 am
Thanks but I couldn't find it. I think I've scoured the entire Google database just about as well. lol I've also tried _MEM with _MEMGET using the Wiki examples for memory blocks, but I'm guessing it doesn't use those addresses for sound. I also looked at the old fashioned way with OUT and INP but QB64 only uses INP for 2 addresses which I don't believe are sound ports. My USB sound card probably wouldn't use that anyway. Petr does any of this sound familiar? Any help is always appreciated.
Title: Re: Sound Question
Post by: Petr on November 01, 2019, 07:05:25 am
Hi SierraKen, You can program the visualization of the sound with QB64. For the function of the program I highly recommend first to write a program that without visualization plays the sound in uncompressed WAV format. This music format is very easy to read and play, unlike compressed MP3 music for example. (Playing WAV is as easy as changing a bulb in a chandelier, playing MP3 is fundamentally, much more complicated.) For visualization, you need detailed knowledge of the internal structure of the WAV file and the _SNDRAW, _SNDRAWLEN commands. Nothing more. But, at the outset, I have two important things to point out to you. First: There is an unknown, uncorrected bug that causes SNDRAW to play very strange stereo, rather mono sound, and that SNDRAW contains an internal buffer that you have to watch for audio and video synchronization, and that is not easy if you want precise visualization . If you look at my YouTube channel, there are some visuals written in QB64. Another thing to note before writing a visualization is that the 16-bit stereo record contains 44100 samples (numbers). If you write the program incorrectly and want to display each sample, then the program will hang. It is necessary to take the mathematical average for the time period and use it for visualization. To load a WAV music file, I recommend wikipedia to find the internal structure of the WAV file (it's not complicated, really) and then you'll read it using the GET command.
I also wrote MP3 playback, but I used a third-party decoder that can save MP3 to RAW format. The RAW format is the same as the WAV format, but without the file header, which is absolutely essential for proper file content playback. This program works only with some MP3 formats, it decodes the MP3 header, which is written so that individual bits of specific bytes carry the necessary information. MP3 is a compression format, so even the header is written in the smallest possible way. The header of the program must be read to know how the content in the RAW file is decompressed (is it mono or stereo sound ?, is it 8 bit, 16 bit, 24 bit sound?) Each such file is read differently, according to this information. After decoding, playback is the same as WAV format.
Unfortunately, there is no function in QB64 that allows direct access to music samples that are sent to the sound card. MEM commands are used only for graphical and array operations, they cannot be used to obtain RAW audio data, so to visualize you need this path to read data from a file + or write your own audio decoder. Apparently this is because QB64 uses third-party music decoders and does not allow licenses. Or, no one thought anyone wanted access to RAW audio data.
This is my audio PLAYER for WAV files WITHOUT visualization:
Also see here: https://www.qb64.org/forum/index.php?topic=1399.msg105829#msg105829
Title: Re: Sound Question
Post by: SierraKen on November 01, 2019, 07:59:06 pm
Thanks Petr. But I am brand new with the GET command and I tried your WAV program, which works great by the way, but not knowing which variable to use or how to use the GET command, I just tried a bunch of things you had on there but couldn't get a variable that changed as the song went along. I also tried Wikipedia and other website about the .WAV file structure which is interesting, but without knowing how to use GET and what code to use, I'm at a loss. But it sure interests me a lot. It might be over my head, especially if I need to know what things to find within the .WAV file that I can't really see right now. I appreciate your help.
Title: Re: Sound Question
Post by: Petr on November 02, 2019, 04:33:39 am
Hi SierraKen. For drawing music curve use my source code and variables LEF and RIGH. This are sound values read from WAV file, always in range -1 to 1 (and -1 to 1 is also valid value for _SNDRAW). You can study my code, which show you how GET works, program read music samples from WAV so as is writed now.
I add small upgraded source code, now with easy visualisation. Do some experiments with it :)
Title: Re: Sound Question
Post by: SierraKen on November 02, 2019, 05:44:40 pm
That is so awesome! Thanks Petr! I added 2 displays as well as yours and changed the way your line goes over the old line, I did a CLS as soon as it gets to the end of the screen. Press the Space Bar to switch between displays. :)