Manipulating sounds C++

Started by
13 comments, last by NicolasJay 12 years, 10 months ago
So here is the deal, after reading and experimenting, I decided to just use SDL_mixer. It has couple of functions that I can use.

First Mix_OpenAudio[color="#7b3f8e"]([font=Monaco][size=2]MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,STEREO,SAMPLE_CHUNK) [/font]
[font=Monaco][size=2]
[/font]
[font=Monaco][size=2]
[/font]
[font=Monaco][size=2]As you said, I realize that sometimes there might be trouble and it might not get the correct default values, but for now this will be the easiest way to approach my project.[/font]
[font=Monaco][size=2]
[/font]
[font=Monaco][size=2]Now [/font][font=Monaco][size=2]Mix_RegisterEffect(CHANNEL,SampleChunkProcessorCallBack,endProcessCallBack, ARG_DATA); [/font]
[font=Monaco][size=2]
[/font]
[font=Monaco][size=2]this would register a callback like you said, to channel CHANNEL. [/font]
[font=Monaco][size=2]
[/font]
[font=Monaco][size=2]And this function [/font][font=Monaco][size=2]Mix_PlayChannel(CHANNEL,music, NUMBER_OF_TIMES_TO_PLAY_AGAIN);[/font]
[font=Monaco][size=2]
[/font]
[font="Monaco"][size=2]so when SDL starts playing music, SampleChunkProcessorCallBack will be called with the sample chunk data and its length. Sample chunk data is of type void, but the[/font]
[font="Monaco"][size=2]its actually a 16bit sample( MIX_DEFAULT_FORMAT => [/font][font=Monaco][size=2]AUDIO_S16LSB => 0x8010 => "16 bit sample" ). [/font]
[font=Monaco][size=2]
[/font]
[font=Monaco][size=2]
[/font]
[font=Monaco][size=2]So now when the callback function is called I do the following:[/font]
[font=Monaco][size=2]
[/font]
[font=Monaco][size=2]1) Convert the void*chunkData into a array of 16 bit values( short int ).[/font]
[font=Monaco][size=2]2) Run DFT( FFT ) on the time domain data, to convert it into frequency domain[/font]
[font=Monaco][size=2]3) Use the Frequency domain information somehow( Frequency domain information contains a vector of realPart and vector of ImaginaryPart ) to get some numerical data[/font]
[font=Monaco][size=2]4) Use that numerical data to display the result on a graph using opengl. Presumably, just display the wave spectrum( if thats whats its called )[/font]
[font=Monaco][size=2]5) Repeat 1[/font]
[font=Monaco][size=2]
[/font]
[font="Monaco"][size=2]I might have to do some filtering and apply some noise reduction technique before displaying it.[/font]
[font="Monaco"][size=2]
[/font]
[font="Monaco"][size=2]What do you think, or anyone else that can help for that matter ?[/font]
[font="Monaco"][size=2]
[/font]
[font="Monaco"][size=2]
[/font]
[font="Monaco"][size=2]regards, D.Chhetri[/font]
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github
Advertisement
May I suggest FFTW for doing the DFT? We used it in uni for a project and it worked out pretty well.

To calculate the amplitude at a certain frequency, you have to take the magnitude of the complex number. i.e sqrt(real^2+imaginary^2)

Depending on the chunk size that SDL throws at you you may see some artifacts in the frequency domain since it is actually a rectangular window function into the waveform.

cheers
Thanks for the tip, what do you mean by artifacts?
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github
With artifacts I mean the following:

The DFT gives you a discrete frequency spectrum. When you sample a chunk of a longer waveform, there will be frequency components present which don't quite fit into the chunk. (i.e chunk length is not an integer multiple of its wavelength).
This will 'smear' the frequency spectrum.
However, I guess for just visualizing music it should be good enough.

Also keep in mind that the lowest frequency detectable by the DFT is restricted by the length of the chunk.
Shorter sample length = better time resoultion, worse frequency resolution
I am actually working on something now where I have to do pretty much all the low level sound stuff by myself =/

anyways, I came across this while researching:
http://www.mixxx.org/download.php

open source dj mixing software. It's quite a bit of code, but still probably a good resource.

anyways, off to continue digging..ugh

This topic is closed to new replies.

Advertisement