19 Jun '13 - 22:04 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Aquiring data from a microphone recording  (Read 923 times)
Reilloch
Posts: 7


« on: 9 Aug '12 - 18:56 »
Reply with quoteQuote

Hello there, 
Using Delphi XE2 (Pascal) I have written a  FFT function however i need to be able to pass it data from a microphone signal. So far i have been unable to work out how to use bass to pass the function the next N values for use in the FFT. Is there a simple function/way to do this which i have overlooked or is it more complex than i first thought?

Thanks in advance
« Last Edit: 10 Aug '12 - 11:22 by Reilloch » Logged
Ian @ un4seen
Administrator
Posts: 15366


« Reply #1 on: 10 Aug '12 - 16:07 »
Reply with quoteQuote

If you would like to receive/process the recorded data in fixed size blocks, you can do so by not using a RECORDPROC callback function, ie. passing NULL to BASS_RecordStart. You can then use BASS_ChannelGetData to get the amount of data that you want. Something like this...

recording=BASS_RecordStart(freq, chans, 0, NULL, NULL); // start recording without a RECORDPROC

...

DWORD avail=BASS_ChannelGetData(recording, NULL, BASS_DATA_AVAILABLE); // get amount of data in the recording buffer
if (avail>=wanted) { // the wanted amount is available
BASS_ChannelGetData(recording, buffer, wanted); // get the wanted amount of data
// process the data...
}
Logged
Reilloch
Posts: 7


« Reply #2 on: 11 Aug '12 - 13:28 »
Reply with quoteQuote

If you would like to receive/process the recorded data in fixed size blocks, you can do so by not using a RECORDPROC callback function, ie. passing NULL to BASS_RecordStart. You can then use BASS_ChannelGetData to get the amount of data that you want. Something like this...

recording=BASS_RecordStart(freq, chans, 0, NULL, NULL); // start recording without a RECORDPROC

...

DWORD avail=BASS_ChannelGetData(recording, NULL, BASS_DATA_AVAILABLE); // get amount of data in the recording buffer
if (avail>=wanted) { // the wanted amount is available
BASS_ChannelGetData(recording, buffer, wanted); // get the wanted amount of data
// process the data...
}

Thank you very much, i shall try this later today
Logged
Reilloch
Posts: 7


« Reply #3 on: 11 Aug '12 - 13:58 »
Reply with quoteQuote

<code>

Function Tform2.Rec;
var
avail:Dword;
begin
repeat
Recording:=Bass_RecordStart(44100,2,0,@NULL,@NULL);//Start recording without Record Proc;
avail:=Bass_ChannelGetData(recording,@Buffer,BASS_DATA_AVAILABLE); // retrieve the ammount of data in the buffer
{if avail>=NB then
BASS_ChannelGetData(Recording,@Buffer,NB);}
until avail>=NB;
BASS_ChannelGetData(Recording,@Buffer,NB);
end;
</Code>

That is the code i have written
with buffer declared in a type like so :
<code>
Buf3 = array [0..NB-1] of extended;
var
Buffer:Buf3;
</code>

This code works however i can't seem to get values other than 0 in the buffer.
Do i need to specify my recording device?
Any suggestions?

Thanks  Smiley
Logged
Chris
Posts: 1507


« Reply #4 on: 11 Aug '12 - 15:57 »
Reply with quoteQuote

Function Tform2.Rec;
var
avail:Dword;
begin
repeat
Recording:=Bass_RecordStart(44100,2,0,@NULL,@NULL);//Start recording without Record Proc;
avail:=Bass_ChannelGetData(recording,@Buffer,BASS_DATA_AVAILABLE); // retrieve the ammount of data in the buffer
{if avail>=NB then
BASS_ChannelGetData(Recording,@Buffer,NB);}
until avail>=NB;
BASS_ChannelGetData(Recording,@Buffer,NB);
end;




bass-recordstart in a while/repeat call makes no sense
should be

Function Tform2.Rec;
var
  avail:Dword;
begin
   Recording:=Bass_RecordStart(44100,2,0,nil,nil);//Start recording without Record Proc;
   while Bass_ChannelIscative(recording)> 0 do
      begin
         avail:=Bass_ChannelGetData(recording,nil,BASS_DATA_AVAILABLE); // retrieve the ammount of data in the buffer
         if avail>=NB then
           BASS_ChannelGetData(Recording,@Buffer,NB);}
      end;
     end;
 end;
« Last Edit: 11 Aug '12 - 16:02 by Chris » Logged
Reilloch
Posts: 7


« Reply #5 on: 11 Aug '12 - 16:27 »
Reply with quoteQuote

I have changed it however buffer is still returning 0 to me. Do i need to specify and initialise my recording device? if so how do i do this?
Logged
Chris
Posts: 1507


« Reply #6 on: 11 Aug '12 - 20:33 »
Reply with quoteQuote

Place after
Recording:=Bass_RecordStart(44100,2,0,nil,nil);//Start recording without Record Proc;
a Bass_ErrorGetCode call to see whats going wrong
Chris
Logged
Reilloch
Posts: 7


« Reply #7 on: 11 Aug '12 - 20:45 »
Reply with quoteQuote

Place after
Recording:=Bass_RecordStart(44100,2,0,nil,nil);//Start recording without Record Proc;
a Bass_ErrorGetCode call to see whats going wrong
Chris

I recieve 8   BASS_ERROR_INIT  - any suggestions?
Logged
Chris
Posts: 1507


« Reply #8 on: 12 Aug '12 - 21:29 »
Reply with quoteQuote

you have to add

procedure TForm2.OnCreate(Sender:TObject);
begin
   Bass_Init(-1, 44100, 0, handle, nil);//-1 the default SoundDevice
end;

procedure TForm2.OnDestroy(Sender:TObject);
begin
   Bass_Free();
end;
« Last Edit: 12 Aug '12 - 23:08 by Chris » Logged
Reilloch
Posts: 7


« Reply #9 on: 13 Aug '12 - 12:16 »
Reply with quoteQuote

thank you for your last response Smiley

The program now works, However After running the program for a while Bass error code 5 pops up. Not quite sure why - this seems to happen after about 50 loops of my main program. Any suggestions as i would like to be able to loop this indefinatley..
« Last Edit: 14 Aug '12 - 19:40 by Reilloch » Logged
Chris
Posts: 1507


« Reply #10 on: 16 Aug '12 - 23:48 »
Reply with quoteQuote

Change it to

Function Tform2.Rec;
var
  avail:Dword;
begin
   Recording:=Bass_RecordStart(44100,2,0,nil,nil);//Start recording without Record Proc;
   while Bass_ChannelIscative(recording)> 0 do
      begin
         avail:=Bass_ChannelGetData(recording,nil,BASS_DATA_AVAILABLE); // retrieve the ammount of data in the buffer
         if avail>=NB then
           BASS_ChannelGetData(Recording,@Buffer,sizeof(Buffer);
      end;
     end;
 end;
Logged
Reilloch
Posts: 7


« Reply #11 on: 20 Aug '12 - 18:20 »
Reply with quoteQuote

This all now works perfectly. One last question, is there a way for me to vary the volume of the microphone recording (like using the windows slider under sound in control panel)?

Thanks
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines