static std::ostream &
Codec2Enumerator(std::ostream & stream)
{
- stream << "\"codec2:1400\" (1200,1300,1400,1600,2400,3200)" << std::endl;
+ stream << "\"codec2:1600\" (1200,1300,1400,1600,2400,3200)" << std::endl;
return stream;
}
///
const unsigned int SamplesPerMillisecond = ((double)SampleRate / 1000.0);
-/// The audio frame duration in milliseconds. The audio interfaces will
-/// use this as a period size. It should be 1/2 of the smallest codec frame
-/// size we expect to use.
-const unsigned int AudioFrameDuration = 10;
/// The number of audio samples in an audio frame. Audio frames must be a
/// power of two (this is a common hardware requirement) and must be shorter
/// than any codec/modem frame in the program.
const unsigned int AudioFrameSamples = 512;
+/// The audio frame duration in milliseconds. The audio interfaces will
+/// use this as a period size.
+const unsigned int AudioFrameDuration = ((double)SampleRate / (double)AudioFrameSamples);
+
/// The number of audio samples in the maximum-duration frame.
/// This must be a power of two (this is a common hardware requirement) and
/// must be at least twice the value of AudioFrameSamples.
///
-const unsigned int MaximumFrameSamples = 32768;
+const unsigned int MaximumFrameSamples = AudioFrameSamples * 2;
/// Allocate memory and copy a string into it, so that it is permanently
/// stored.
error = open_by_longname(&handle, name, stream, mode);
if ( error < 0 ) {
- error = snd_pcm_open(
- &handle,
- name,
- stream,
- mode);
-
- if ( error < 0 )
- return 0;
+ if ( strcmp(name, "default") == 0
+ || strncmp(name, "hw:", 3) == 0
+ || strncmp(name, "plughw:", 7) == 0 ) {
+ error = snd_pcm_open(
+ &handle,
+ name,
+ stream,
+ mode);
+ }
}
+ if ( error < 0 )
+ return 0;
try {
if ( (error = snd_pcm_hw_params_malloc(&hw_params)) < 0 )
///
class AudioInALSA : public AudioInput {
private:
- static const int overlong_delay = AudioFrameSamples * 4;
+ static const int overlong_delay = AudioFrameSamples * 8;
snd_pcm_t * handle;
char * const parameters;
}
if ( out_fifo.get_available() > 0 ) {
+ // std::cerr << out_fifo.get_available() / 2 << ' ';
// There are samples queued for the loudspeaker. Wake when there is room
// in its buffer.
if ( output_fd_base < 0 ) {
struct timespec request;
struct timespec remainder;
request.tv_sec = 0;
- request.tv_nsec = AudioFrameDuration * 1000000;
+ request.tv_nsec = AudioFrameDuration * 1000000;
nanosleep(&request, &remainder);
}
///
class Tone : public AudioInput {
private:
- unsigned int clock;
+ unsigned long long clock;
struct tone_info {
float frequency;
value * master_amplitude * ((1 << 15) - 1));
array[i] = v;
}
- clock = (clock + length) % SampleRate;
+ clock = (clock + length);
return length;
}