-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return devices #58
Return devices #58
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,48 @@ | ||
#include "pa_devices.h" | ||
|
||
UNIFEX_TERM list(UnifexEnv *env) { | ||
UNIFEX_TERM list(UnifexEnv *env) | ||
{ | ||
Pa_Initialize(); | ||
int numDevices = Pa_GetDeviceCount(); | ||
if (numDevices < 0) { | ||
device devices[numDevices]; | ||
char names[numDevices][255]; | ||
if (numDevices < 0) | ||
{ | ||
printf("\nERROR: Pa_CountDevices returned 0x%x\n", numDevices); | ||
return list_result(env); | ||
} else if (numDevices == 0) { | ||
return list_result_ok(env, devices, numDevices); | ||
} | ||
else if (numDevices == 0) | ||
{ | ||
printf("\nNo audio devices found\n"); | ||
} else { | ||
} | ||
else | ||
{ | ||
printf("\nAvailable audio devices:\n\n"); | ||
int default_input_id = Pa_GetDefaultInputDevice(); | ||
int default_output_id = Pa_GetDefaultOutputDevice(); | ||
for (int i = 0; i < numDevices; i++) { | ||
for (int i = 0; i < numDevices; i++) | ||
{ | ||
const PaDeviceInfo *device_info = Pa_GetDeviceInfo(i); | ||
const char *default_str = | ||
i == default_input_id | ||
? " (default input)" | ||
: i == default_output_id ? " (default output)" : ""; | ||
: i == default_output_id ? " (default output)" | ||
: ""; | ||
|
||
printf("%s%s\r\n\tid: %d\r\n\tmax_input_channels: " | ||
"%d\r\n\tmax_output_channels: %d\r\n\n", | ||
device_info->name, default_str, i, device_info->maxInputChannels, | ||
device_info->maxOutputChannels); | ||
johns10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
strncpy(names[i], device_info->name, 255); | ||
|
||
devices[i].id = i; | ||
devices[i].name = names[i]; | ||
devices[i].max_output_channels = device_info->maxOutputChannels; | ||
devices[i].max_input_channels = device_info->maxInputChannels; | ||
} | ||
} | ||
|
||
Pa_Terminate(); | ||
return list_result(env); | ||
return list_result_ok(env, devices, numDevices); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,12 @@ | ||||||||||||||||||||||
module Membrane.PortAudio.Devices | ||||||||||||||||||||||
|
||||||||||||||||||||||
spec list() :: :ok | ||||||||||||||||||||||
type( | ||||||||||||||||||||||
device :: %Device{ | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Also, let's create a corresponding struct in a |
||||||||||||||||||||||
id: int, | ||||||||||||||||||||||
name: string, | ||||||||||||||||||||||
max_input_channels: int, | ||||||||||||||||||||||
max_output_channels: int | ||||||||||||||||||||||
} | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Then you can use that like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had added is_default, will move to this instead. |
||||||||||||||||||||||
spec list() :: {:ok :: label, devices :: [device]} | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if
numDevices
is negative? :P Also, I'd allocate this on the heap just in casenumDevices
is big for some reason