summaryrefslogtreecommitdiffstats
path: root/parecord/audio_types.c
diff options
context:
space:
mode:
Diffstat (limited to 'parecord/audio_types.c')
-rw-r--r--parecord/audio_types.c73
1 files changed, 50 insertions, 23 deletions
diff --git a/parecord/audio_types.c b/parecord/audio_types.c
index eda78bd..bcf6a05 100644
--- a/parecord/audio_types.c
+++ b/parecord/audio_types.c
@@ -1,27 +1,28 @@
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "audio_types.h"
-static const struct audio_types_info support_types[] = {
- {"wav", 44}, // AUDIO_TYPE_WAVE
- {NULL, 0}
+static const struct audio_types_info support_types[AUDIO_TYPE_MAX] = {
+ {"wav", 44}
};
-static const struct audio_formats_info support_formats[] = {
- {"U8", PA_SAMPLE_U8},
- {"A_LAW", PA_SAMPLE_ALAW},
- {"MU_LAW", PA_SAMPLE_ULAW},
- {"S16_LE", PA_SAMPLE_S16LE},
- {"S16_BE", PA_SAMPLE_S16BE},
- {"FLOAT32_LE", PA_SAMPLE_FLOAT32LE},
- {"FLOAT32_BE", PA_SAMPLE_FLOAT32BE},
- {"S32_LE", PA_SAMPLE_S32LE},
- {"S32_BE", PA_SAMPLE_S32BE},
- {"S24_LE", PA_SAMPLE_S24LE},
- {"S24_BE", PA_SAMPLE_S24BE},
- {"S24_32LE", PA_SAMPLE_S24_32LE},
- {"S24_32BE", PA_SAMPLE_S24_32BE},
- {NULL, 0}
+static const char
+ audio_format_name[AUDIO_FORMAT_MAX][MAX_AUDIO_FORMAT_LEN] = {
+ "U8",
+ "A_LAW",
+ "MU_LAW",
+ "S16_LE",
+ "S16_BE",
+ "FLOAT32_LE",
+ "FLOAT32_BE",
+ "S32_LE",
+ "S32_BE",
+ "S24_LE",
+ "S24_BE",
+ "S24_32LE",
+ "S24_32BE"
};
struct wav_header *init_wav_header(struct wav_header *header,
@@ -48,7 +49,7 @@ struct wav_header *init_wav_header(struct wav_header *header,
int checkAudioType(char *source)
{
int i;
- for(i = 0; support_types[i].name != NULL; i++) {
+ for(i = 0; i < AUDIO_TYPE_MAX; i++) {
if(strcmp(source, support_types[i].name) == 0) {
return i;
}
@@ -57,19 +58,45 @@ int checkAudioType(char *source)
return AUDIO_TYPE_NONE;
}
+char *getAllAudioTypes()
+{
+ int i;
+ char *dest = malloc(sizeof(char) * MAX_AUDIO_TYPE_LEN *
+ AUDIO_TYPE_MAX + sizeof(char));
+ char *str = dest;
+ for(i = 0; i < AUDIO_TYPE_MAX; i++) {
+ str += sprintf(str, " %s", support_types[i].name);
+ }
+
+ return dest;
+}
+
off_t getOffset(int format)
{
return support_types[format].rsv_bytes;
}
-pa_sample_format_t checkAudioFormat(char *source)
+int checkAudioFormat(char *source)
{
int i;
- for(i = 0; support_formats[i].name != NULL; i++) {
- if(strcmp(source, support_formats[i].name) == 0) {
- return support_formats[i].pa_format;
+ for(i = 0; i < AUDIO_FORMAT_MAX; i++) {
+ if(strcmp(source, audio_format_name[i]) == 0) {
+ return i;
}
}
return PA_SAMPLE_INVALID;
+}
+
+char *getAllAudioFormats()
+{
+ int i;
+ char *dest = malloc(sizeof(char) * MAX_AUDIO_FORMAT_LEN *
+ AUDIO_FORMAT_MAX + sizeof(char));
+ char *str = dest;
+ for(i = 0; i < AUDIO_FORMAT_MAX; i++) {
+ str += sprintf(str, " %s", audio_format_name[i]);
+ }
+
+ return dest;
} \ No newline at end of file