<font color="#000066">While trying to record 44100 Hz it records the file as record.raw and i can use the sample to test it. But when i try to record as 48000 sample rate or above, it does nothing.</font><div><font class="Apple-style-span" color="#000066"><br>
</font></div><div><font class="Apple-style-span" color="#000066"><div>uname -a : Linux example 2.6.32.12-114.fc12.i686 #1 SMP Tue Apr 27 21:29:58 UTC 2010 i686 i686 i386 GNU/Linux</div><div><br></div></font></div><div><font class="Apple-style-span" color="#000066"><br>
</font></div><div><font class="Apple-style-span" color="#000066">Here is my code record.cpp:</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><div><font class="Apple-style-span" color="#000066">/******************************************/</font></div>
<div><font class="Apple-style-span" color="#000066">/*</font></div><div><font class="Apple-style-span" color="#000066">  record.cpp</font></div><div><font class="Apple-style-span" color="#000066">  by Gary P. Scavone, 2007</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  This program records audio from a device and writes it to a</font></div><div><font class="Apple-style-span" color="#000066">  header-less binary file.  Use the &#39;playraw&#39;, with the same</font></div>
<div><font class="Apple-style-span" color="#000066">  parameters and format settings, to playback the audio.</font></div><div><font class="Apple-style-span" color="#000066">*/</font></div><div><font class="Apple-style-span" color="#000066">/******************************************/</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">#include &quot;RtAudio.h&quot;</font></div><div><font class="Apple-style-span" color="#000066">#include &lt;iostream&gt;</font></div>
<div><font class="Apple-style-span" color="#000066">#include &lt;cstdlib&gt;</font></div><div><font class="Apple-style-span" color="#000066">#include &lt;cstring&gt;</font></div><div><font class="Apple-style-span" color="#000066">#include &lt;stdio.h&gt;</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">/*</font></div><div><font class="Apple-style-span" color="#000066">typedef char  MY_TYPE;</font></div>
<div><font class="Apple-style-span" color="#000066">#define FORMAT RTAUDIO_SINT8</font></div><div><font class="Apple-style-span" color="#000066">*/</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div>
<div><font class="Apple-style-span" color="#000066">typedef signed short  MY_TYPE;</font></div><div><font class="Apple-style-span" color="#000066">#define FORMAT RTAUDIO_SINT16</font></div><div><font class="Apple-style-span" color="#000066"><br>
</font></div><div><font class="Apple-style-span" color="#000066">/*</font></div><div><font class="Apple-style-span" color="#000066">typedef signed long  MY_TYPE;</font></div><div><font class="Apple-style-span" color="#000066">#define FORMAT RTAUDIO_SINT24</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">typedef signed long  MY_TYPE;</font></div><div><font class="Apple-style-span" color="#000066">#define FORMAT RTAUDIO_SINT32</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">typedef float  MY_TYPE;</font></div><div><font class="Apple-style-span" color="#000066">#define FORMAT RTAUDIO_FLOAT32</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">typedef double  MY_TYPE;</font></div><div><font class="Apple-style-span" color="#000066">#define FORMAT RTAUDIO_FLOAT64</font></div>
<div><font class="Apple-style-span" color="#000066">*/</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">// Platform-dependent sleep routines.</font></div>
<div><font class="Apple-style-span" color="#000066">#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ )</font></div><div><font class="Apple-style-span" color="#000066">  #include &lt;windows.h&gt;</font></div><div>
<font class="Apple-style-span" color="#000066">  #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) </font></div><div><font class="Apple-style-span" color="#000066">#else // Unix variants</font></div><div><font class="Apple-style-span" color="#000066">  #include &lt;unistd.h&gt;</font></div>
<div><font class="Apple-style-span" color="#000066">  #define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )</font></div><div><font class="Apple-style-span" color="#000066">#endif</font></div><div>
<font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">void usage( void ) {</font></div><div><font class="Apple-style-span" color="#000066">  // Error function in case of incorrect command-line</font></div>
<div><font class="Apple-style-span" color="#000066">  // argument specifications</font></div><div><font class="Apple-style-span" color="#000066">  std::cout &lt;&lt; &quot;\nuseage: record N fs &lt;duration&gt; &lt;device&gt; &lt;channelOffset&gt;\n&quot;;</font></div>
<div><font class="Apple-style-span" color="#000066">  std::cout &lt;&lt; &quot;    where N = number of channels,\n&quot;;</font></div><div><font class="Apple-style-span" color="#000066">  std::cout &lt;&lt; &quot;    fs = the sample rate,\n&quot;;</font></div>
<div><font class="Apple-style-span" color="#000066">  std::cout &lt;&lt; &quot;    duration = optional time in seconds to record (default = 2.0),\n&quot;;</font></div><div><font class="Apple-style-span" color="#000066">  std::cout &lt;&lt; &quot;    device = optional device to use (default = 0),\n&quot;;</font></div>
<div><font class="Apple-style-span" color="#000066">  std::cout &lt;&lt; &quot;    and channelOffset = an optional channel offset on the device (default = 0).\n\n&quot;;</font></div><div><font class="Apple-style-span" color="#000066">  exit( 0 );</font></div>
<div><font class="Apple-style-span" color="#000066">}</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">struct InputData {</font></div><div>
<font class="Apple-style-span" color="#000066">  MY_TYPE* buffer;</font></div><div><font class="Apple-style-span" color="#000066">  unsigned long bufferBytes;</font></div><div><font class="Apple-style-span" color="#000066">  unsigned long totalFrames;</font></div>
<div><font class="Apple-style-span" color="#000066">  unsigned long frameCounter;</font></div><div><font class="Apple-style-span" color="#000066">  unsigned int channels;</font></div><div><font class="Apple-style-span" color="#000066">};</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">// Interleaved buffers</font></div><div><font class="Apple-style-span" color="#000066">int input( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,</font></div>
<div><font class="Apple-style-span" color="#000066">           double streamTime, RtAudioStreamStatus status, void *data )</font></div><div><font class="Apple-style-span" color="#000066">{</font></div><div><font class="Apple-style-span" color="#000066">  InputData *iData = (InputData *) data;</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  // Simply copy the data to our allocated buffer.</font></div><div><font class="Apple-style-span" color="#000066">  unsigned int frames = nBufferFrames;</font></div>
<div><font class="Apple-style-span" color="#000066">  if ( iData-&gt;frameCounter + nBufferFrames &gt; iData-&gt;totalFrames ) {</font></div><div><font class="Apple-style-span" color="#000066">    frames = iData-&gt;totalFrames - iData-&gt;frameCounter;</font></div>
<div><font class="Apple-style-span" color="#000066">    iData-&gt;bufferBytes = frames * iData-&gt;channels * sizeof( MY_TYPE );</font></div><div><font class="Apple-style-span" color="#000066">  }</font></div><div><font class="Apple-style-span" color="#000066"><br>
</font></div><div><font class="Apple-style-span" color="#000066">  unsigned long offset = iData-&gt;frameCounter * iData-&gt;channels;</font></div><div><font class="Apple-style-span" color="#000066">  memcpy( iData-&gt;buffer+offset, inputBuffer, iData-&gt;bufferBytes );</font></div>
<div><font class="Apple-style-span" color="#000066">  iData-&gt;frameCounter += frames;</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  if ( iData-&gt;frameCounter &gt;= iData-&gt;totalFrames ) return 2;</font></div>
<div><font class="Apple-style-span" color="#000066">  return 0;</font></div><div><font class="Apple-style-span" color="#000066">}</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">int main( int argc, char *argv[] )</font></div>
<div><font class="Apple-style-span" color="#000066">{</font></div><div><font class="Apple-style-span" color="#000066">  unsigned int channels, fs, bufferFrames, device = 0, offset = 0;</font></div><div><font class="Apple-style-span" color="#000066">  double time = 2.0;</font></div>
<div><font class="Apple-style-span" color="#000066">  FILE *fd;</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  // minimal command-line checking</font></div>
<div><font class="Apple-style-span" color="#000066">  if ( argc &lt; 3 || argc &gt; 6 ) usage();</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  RtAudio adc;</font></div>
<div><font class="Apple-style-span" color="#000066">  if ( adc.getDeviceCount() &lt; 1 ) {</font></div><div><font class="Apple-style-span" color="#000066">    std::cout &lt;&lt; &quot;\nNo audio devices found!\n&quot;;</font></div>
<div><font class="Apple-style-span" color="#000066">    exit( 1 );</font></div><div><font class="Apple-style-span" color="#000066">  }</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div>
<font class="Apple-style-span" color="#000066">  channels = (unsigned int) atoi( argv[1] );</font></div><div><font class="Apple-style-span" color="#000066">  fs = (unsigned int) atoi( argv[2] );</font></div><div><font class="Apple-style-span" color="#000066">  if ( argc &gt; 3 )</font></div>
<div><font class="Apple-style-span" color="#000066">    time = (double) atof( argv[3] );</font></div><div><font class="Apple-style-span" color="#000066">  if ( argc &gt; 4 )</font></div><div><font class="Apple-style-span" color="#000066">    device = (unsigned int) atoi( argv[4] );</font></div>
<div><font class="Apple-style-span" color="#000066">  if ( argc &gt; 5 )</font></div><div><font class="Apple-style-span" color="#000066">    offset = (unsigned int) atoi( argv[5] );</font></div><div><font class="Apple-style-span" color="#000066"><br>
</font></div><div><font class="Apple-style-span" color="#000066">  // Let RtAudio print messages to stderr.</font></div><div><font class="Apple-style-span" color="#000066">  adc.showWarnings( true );</font></div><div><font class="Apple-style-span" color="#000066"><br>
</font></div><div><font class="Apple-style-span" color="#000066">  // Set our stream parameters for input only.</font></div><div><font class="Apple-style-span" color="#000066">  bufferFrames = 512;</font></div><div><font class="Apple-style-span" color="#000066">  RtAudio::StreamParameters iParams;</font></div>
<div><font class="Apple-style-span" color="#000066">  iParams.deviceId = device;</font></div><div><font class="Apple-style-span" color="#000066">  iParams.nChannels = channels;</font></div><div><font class="Apple-style-span" color="#000066">  iParams.firstChannel = offset;</font></div>
<div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  InputData data;</font></div><div><font class="Apple-style-span" color="#000066">  data.buffer = 0;</font></div>
<div><font class="Apple-style-span" color="#000066">  try {</font></div><div><font class="Apple-style-span" color="#000066">    adc.openStream( NULL, &amp;iParams, FORMAT, fs, &amp;bufferFrames, &amp;input, (void *)&amp;data );</font></div>
<div><font class="Apple-style-span" color="#000066">  }</font></div><div><font class="Apple-style-span" color="#000066">  catch ( RtError&amp; e ) {</font></div><div><font class="Apple-style-span" color="#000066">    std::cout &lt;&lt; &#39;\n&#39; &lt;&lt; e.getMessage() &lt;&lt; &#39;\n&#39; &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" color="#000066">    goto cleanup;</font></div><div><font class="Apple-style-span" color="#000066">  }</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div>
<font class="Apple-style-span" color="#000066">  data.bufferBytes = bufferFrames * channels * sizeof( MY_TYPE );</font></div><div><font class="Apple-style-span" color="#000066">  data.totalFrames = (unsigned long) (fs * time);</font></div>
<div><font class="Apple-style-span" color="#000066">  data.frameCounter = 0;</font></div><div><font class="Apple-style-span" color="#000066">  data.channels = channels;</font></div><div><font class="Apple-style-span" color="#000066">  unsigned long totalBytes;</font></div>
<div><font class="Apple-style-span" color="#000066">  totalBytes = data.totalFrames * channels * sizeof( MY_TYPE );</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  // Allocate the entire data buffer before starting stream.</font></div>
<div><font class="Apple-style-span" color="#000066">  data.buffer = (MY_TYPE*) malloc( totalBytes );</font></div><div><font class="Apple-style-span" color="#000066">  if ( data.buffer == 0 ) {</font></div><div><font class="Apple-style-span" color="#000066">    std::cout &lt;&lt; &quot;Memory allocation error ... quitting!\n&quot;;</font></div>
<div><font class="Apple-style-span" color="#000066">    goto cleanup;</font></div><div><font class="Apple-style-span" color="#000066">  }</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div>
<font class="Apple-style-span" color="#000066">  try {</font></div><div><font class="Apple-style-span" color="#000066">    adc.startStream();</font></div><div><font class="Apple-style-span" color="#000066">  }</font></div>
<div><font class="Apple-style-span" color="#000066">  catch ( RtError&amp; e ) {</font></div><div><font class="Apple-style-span" color="#000066">    std::cout &lt;&lt; &#39;\n&#39; &lt;&lt; e.getMessage() &lt;&lt; &#39;\n&#39; &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" color="#000066">    goto cleanup;</font></div><div><font class="Apple-style-span" color="#000066">  }</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div>
<font class="Apple-style-span" color="#000066">  std::cout &lt;&lt; &quot;\nRecording for &quot; &lt;&lt; time &lt;&lt; &quot; seconds ... writing file &#39;record.raw&#39; (buffer frames = &quot; &lt;&lt; bufferFrames &lt;&lt; &quot;).&quot; &lt;&lt; std::endl;</font></div>
<div><font class="Apple-style-span" color="#000066">  while ( adc.isStreamRunning() ) {</font></div><div><font class="Apple-style-span" color="#000066">    SLEEP( 100 ); // wake every 100 ms to check if we&#39;re done</font></div>
<div><font class="Apple-style-span" color="#000066">  }</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  // Now write the entire data to the file.</font></div>
<div><font class="Apple-style-span" color="#000066">  fd = fopen( &quot;record.raw&quot;, &quot;wb&quot; );</font></div><div><font class="Apple-style-span" color="#000066">  fwrite( data.buffer, sizeof( MY_TYPE ), data.totalFrames * channels, fd );</font></div>
<div><font class="Apple-style-span" color="#000066">  fclose( fd );</font></div><div><font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066"> cleanup:</font></div>
<div><font class="Apple-style-span" color="#000066">  if ( adc.isStreamOpen() ) adc.closeStream();</font></div><div><font class="Apple-style-span" color="#000066">  if ( data.buffer ) free( data.buffer );</font></div><div>
<font class="Apple-style-span" color="#000066"><br></font></div><div><font class="Apple-style-span" color="#000066">  return 0;</font></div><div><font class="Apple-style-span" color="#000066">}</font></div><div style="color: rgb(0, 0, 102); ">
<br></div></div>