Question

After messing a bit with portaudio in my spare time I tried to transmit a frequency while the microphone is open, I wrote a callback for doing so - the callback opens only an output stream and then I use the record callback of portaudio.If the sample format for the output is defined to paFloat32 nothing is heard but if I define it to paUInt8 and number of channels 1 so I hear a sound(like the beep() sound)but the pitch detecting (using FFT) is not the same as the frequency I transmit. So my question is it because the FFT is wrongly implemented (Or - is it possible to use paUint8 and still get a correct answer) or should I try using blocking I/O?

some code (maybe it would help):

this is the output parameters for the output stream (the input stream is from the recording example).

    outputParameters.device = Pa_GetDefaultOutputDevice(); 
    outputParameters.channelCount = 1;      
    outputParameters.sampleFormat = paUInt8; 
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
    outputParameters.hostApiSpecificStreamInfo = NULL;

P.S: Any explanations of why is it possible to transmit with paUInt8 although I used 2 callbacks (1 for reading and one for writing).

Was it helpful?

Solution

It's impossible to know where the problem is without more code, but I can say a few things:

  • Switching to blocking won't make any difference to solving the problem you have.

  • If you don't hear anything when doing paFloat32, you are probably doing something wrong because support for paFloat32 is extremely good. The floating point type has a range between -1 and 1. Make sure that's what you are outputting. You can also try some of the great code samples included with PortAudio. Look for one that outputs using paFloat32 using callbacks and see if it works (like this one).

  • If you are getting the wrong pitch with your FFT detection, you are probably doing that wrong as well. There are two possibilities: 1. the pitch is not what you think it is, and 2. your FFT pitch detection is wrong. Without code, I can only guess, but since EVERYBODY has trouble with #2 (judging by questions on SO), I'm guessing you are having trouble with at least that.

For FFT pitch detection, check out my blog entry complete with code (it even uses portaudio)

http://blog.bjornroche.com/2012/07/frequency-detection-using-fft-aka-pitch.html

For creating the right pitch, there are plenty of questions here on SO.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top