Compare commits
2 Commits
fe87dc6ec8
...
4a83ad2a30
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a83ad2a30 | ||
|
|
826ca13fe1 |
@@ -15,6 +15,52 @@ alsa_read_class::alsa_read_class()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int alsa_read_class::find_usb_capture_device(char *name, size_t name_size)
|
||||||
|
{
|
||||||
|
int card = -1;
|
||||||
|
int found = -1;
|
||||||
|
|
||||||
|
while (found != 0 && snd_card_next(&card) == 0 && card >= 0)
|
||||||
|
{
|
||||||
|
char ctl_name[32];
|
||||||
|
snd_ctl_t *ctl;
|
||||||
|
snd_ctl_card_info_t *info;
|
||||||
|
|
||||||
|
snprintf(ctl_name, sizeof(ctl_name), "hw:%d", card);
|
||||||
|
if (snd_ctl_open(&ctl, ctl_name, 0) < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snd_ctl_card_info_alloca(&info);
|
||||||
|
if (snd_ctl_card_info(ctl, info) == 0 &&
|
||||||
|
strcmp(snd_ctl_card_info_get_driver(info), "USB-Audio") == 0)
|
||||||
|
{
|
||||||
|
// Look for a PCM device on this card that supports capture
|
||||||
|
int dev = -1;
|
||||||
|
snd_pcm_info_t *pcm_info;
|
||||||
|
snd_pcm_info_alloca(&pcm_info);
|
||||||
|
|
||||||
|
while (snd_ctl_pcm_next_device(ctl, &dev) == 0 && dev >= 0)
|
||||||
|
{
|
||||||
|
snd_pcm_info_set_device(pcm_info, dev);
|
||||||
|
snd_pcm_info_set_subdevice(pcm_info, 0);
|
||||||
|
snd_pcm_info_set_stream(pcm_info, SND_PCM_STREAM_CAPTURE);
|
||||||
|
if (snd_ctl_pcm_info(ctl, pcm_info) == 0)
|
||||||
|
{
|
||||||
|
snprintf(name, name_size, "plughw:CARD=%s,DEV=%d",
|
||||||
|
snd_ctl_card_info_get_id(info), dev);
|
||||||
|
printf("found USB capture device: %s (%s)\n",
|
||||||
|
name, snd_ctl_card_info_get_name(info));
|
||||||
|
found = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snd_ctl_close(ctl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
INPUT_SOUND_DATA_TYPE *alsa_read_class::initialize_alsa(char *device_name)
|
INPUT_SOUND_DATA_TYPE *alsa_read_class::initialize_alsa(char *device_name)
|
||||||
{
|
{
|
||||||
rate = SAMPLE_RATE;
|
rate = SAMPLE_RATE;
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ double piano_process_class::goertzel(int num_samples, int target_frequency, int
|
|||||||
q2 = q1;
|
q2 = q1;
|
||||||
q1 = q0;
|
q1 = q0;
|
||||||
q0 = coeff * q1 - q2 + dinput_buffer;
|
q0 = coeff * q1 - q2 + dinput_buffer;
|
||||||
// printf("q0 %f; dinput_buffer %f: integer_input_buffer %d\n", q0, dinput_buffer, *(input_buffer + i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seconod stage (FIR filter)
|
// Seconod stage (FIR filter)
|
||||||
@@ -61,9 +60,6 @@ double piano_process_class::goertzel(int num_samples, int target_frequency, int
|
|||||||
|
|
||||||
// Test Prints
|
// Test Prints
|
||||||
|
|
||||||
// printf("doublesamples %f; scalingfactor %f; k %d\n", doublenumsamples, scalingfactor, k);
|
|
||||||
// printf("omega %f; sine %f; cosine %f; coeff %f\n", omega, sine, cosine, coeff);
|
|
||||||
printf("magnatude %f\n", magnatude);
|
|
||||||
|
|
||||||
// printf("goertzel done\n");
|
// printf("goertzel done\n");
|
||||||
return magnatude;
|
return magnatude;
|
||||||
|
|||||||
15
scope.cpp
15
scope.cpp
@@ -62,8 +62,19 @@ int main(int argc, char *argv[])
|
|||||||
int *return_spectrum_buffer;
|
int *return_spectrum_buffer;
|
||||||
|
|
||||||
printf ("window is %d by %d\n", x_window_size, y_window_size);
|
printf ("window is %d by %d\n", x_window_size, y_window_size);
|
||||||
// char *device_name = (char *)"plughw:CARD=Camcra,DEV=0";
|
// Audio device: use argv[3] if given, otherwise the first USB capture device
|
||||||
char *device_name = (char *)"plughw:CARD=CMTECK,DEV=0";
|
char *device_name = input_our_audio_device_name;
|
||||||
|
if (argc > 3)
|
||||||
|
{
|
||||||
|
snprintf(device_name, sizeof(input_our_audio_device_name), "%s", argv[3]);
|
||||||
|
}
|
||||||
|
else if (alsa_read_class::find_usb_capture_device(device_name,
|
||||||
|
sizeof(input_our_audio_device_name)) != 0)
|
||||||
|
{
|
||||||
|
printf("no USB audio capture device found\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
printf("using audio device %s\n", device_name);
|
||||||
|
|
||||||
|
|
||||||
// returns zero on success else non-zero
|
// returns zero on success else non-zero
|
||||||
|
|||||||
3
scope.h
3
scope.h
@@ -77,6 +77,9 @@ class alsa_read_class {
|
|||||||
alsa_read_class();
|
alsa_read_class();
|
||||||
INPUT_SOUND_DATA_TYPE *initialize_alsa(char *device_name);
|
INPUT_SOUND_DATA_TYPE *initialize_alsa(char *device_name);
|
||||||
int read_alsa();
|
int read_alsa();
|
||||||
|
// Finds the first USB audio card with a capture device and writes
|
||||||
|
// "plughw:CARD=<id>,DEV=<n>" into name. Returns 0 on success, -1 if none.
|
||||||
|
static int find_usb_capture_device(char *name, size_t name_size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
INPUT_SOUND_DATA_TYPE *alsa_input_data;
|
INPUT_SOUND_DATA_TYPE *alsa_input_data;
|
||||||
|
|||||||
Reference in New Issue
Block a user