Changeset 346643c in mainline for uspace/app
- Timestamp:
- 2012-07-11T12:05:30Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 039337e8
- Parents:
- 94694a4
- Location:
- uspace/app
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dplay/dplay.c
r94694a4 r346643c 112 112 113 113 114 static void play(playback_t *pb, unsigned sampling_rate, unsigned sample_size,115 unsigned channels, bool sign)114 static void play(playback_t *pb, unsigned channels, unsigned sampling_rate, 115 pcm_sample_format_t format) 116 116 { 117 117 assert(pb); 118 118 assert(pb->device); 119 119 pb->buffer.position = pb->buffer.base; 120 printf("Playing: %dHz, % d-bit %ssigned samples, %d channel(s).\n",121 sampling_rate, sample_size, sign ? "": "un", channels);120 printf("Playing: %dHz, %s, %d channel(s).\n", 121 sampling_rate, pcm_sample_format_str(format), channels); 122 122 const size_t bytes = fread(pb->buffer.base, sizeof(uint8_t), 123 123 pb->buffer.size, pb->source); … … 127 127 fibril_mutex_lock(&pb->mutex); 128 128 int ret = audio_pcm_start_playback(pb->device, pb->buffer.id, 129 SUBBUFFERS, sampling_rate, sample_size, channels, sign);129 SUBBUFFERS, channels, sampling_rate, format); 130 130 if (ret != EOK) { 131 131 fibril_mutex_unlock(&pb->mutex); … … 212 212 wave_header_t header; 213 213 fread(&header, sizeof(header), 1, pb.source); 214 unsigned rate, sample_size,channels;215 bool sign;214 unsigned rate, channels; 215 pcm_sample_format_t format; 216 216 const char *error; 217 ret = wav_parse_header(&header, NULL, NULL, & rate, &sample_size,218 & channels, &sign, &error);217 ret = wav_parse_header(&header, NULL, NULL, &channels, &rate, &format, 218 &error); 219 219 if (ret != EOK) { 220 220 printf("Error parsing wav header: %s.\n", error); … … 223 223 } 224 224 225 play(&pb, rate, sample_size, channels, sign);225 play(&pb, channels, rate, format); 226 226 fclose(pb.source); 227 227 -
uspace/app/dplay/wave.c
r94694a4 r346643c 40 40 41 41 int wav_parse_header(void *file, const void **data, size_t *data_size, 42 unsigned * sampling_rate, unsigned *sample_size, unsigned *channels,43 bool *sign,const char **error)42 unsigned *channels, unsigned *sampling_rate, pcm_sample_format_t *format, 43 const char **error) 44 44 { 45 45 if (!file) { … … 86 86 } 87 87 88 88 89 if (data) 89 90 *data = header->data; … … 93 94 if (sampling_rate) 94 95 *sampling_rate = uint32_t_le2host(header->sampling_rate); 95 if (sample_size)96 *sample_size = uint32_t_le2host(header->sample_size);97 96 if (channels) 98 97 *channels = uint16_t_le2host(header->channels); 99 if (sign) 100 *sign = uint32_t_le2host(header->sample_size) == 16 101 ? true : false; 98 if (format) { 99 const unsigned size = uint32_t_le2host(header->sample_size); 100 switch (size) { 101 case 8: *format = PCM_SAMPLE_UINT8; break; 102 case 16: *format = PCM_SAMPLE_SINT16_LE; break; 103 case 24: *format = PCM_SAMPLE_SINT24_LE; break; 104 case 32: *format = PCM_SAMPLE_SINT32_LE; break; 105 default: 106 *error = "Unknown format"; 107 return ENOTSUP; 108 } 109 } 102 110 if (error) 103 111 *error = "no error"; -
uspace/app/dplay/wave.h
r94694a4 r346643c 37 37 #include <stdint.h> 38 38 #include <bool.h> 39 #include <pcm_sample_format.h> 39 40 40 41 /** Wave file header format. … … 90 91 91 92 int wav_parse_header(void *, const void**, size_t *, unsigned *, unsigned *, 92 unsigned *, bool *, const char **error_str);93 pcm_sample_format_t *, const char **); 93 94 94 95 #endif -
uspace/app/drec/drec.c
r94694a4 r346643c 47 47 #include <stdio.h> 48 48 #include <macros.h> 49 #include <pcm_sample_format.h> 49 50 50 51 #include "wave.h" … … 53 54 #define SUBBUFFERS 2 54 55 55 const unsigned sampling_rate = 44100, sample_size = 16, channels = 2;56 bool sign = true;56 const unsigned sampling_rate = 44100, channels = 2, sample_size = 16; 57 const pcm_sample_format_t format = PCM_SAMPLE_SINT16_LE; 57 58 58 59 typedef struct { … … 104 105 105 106 106 static void record(record_t *rec, unsigned sampling_rate, unsigned sample_size,107 unsigned channels, bool sign)107 static void record(record_t *rec, unsigned channels, unsigned sampling_rate, 108 pcm_sample_format_t format) 108 109 { 109 110 assert(rec); 110 111 assert(rec->device); 111 112 rec->buffer.position = rec->buffer.base; 112 printf("Recording: %dHz, % d-bit %ssigned samples, %d channel(s).\n",113 sampling_rate, sample_size, sign ? "": "un", channels);113 printf("Recording: %dHz, %s, %d channel(s).\n", 114 sampling_rate, pcm_sample_format_str(format), channels); 114 115 int ret = audio_pcm_start_record(rec->device, rec->buffer.id, 115 SUBBUFFERS, sampling_rate, sample_size, channels, sign);116 SUBBUFFERS, channels, sampling_rate, format); 116 117 if (ret != EOK) { 117 118 printf("Failed to start recording: %s.\n", str_error(ret)); … … 201 202 .sampling_rate = sampling_rate, 202 203 .sample_size = sample_size, 203 .byte_rate = (sampling_rate / 8) * channels,204 .block_align = (sampl ing_rate / 8) * channels,204 .byte_rate = sampling_rate * (sample_size / 8) * channels, 205 .block_align = (sample_size / 8) * channels, 205 206 .subchunk2_id = SUBCHUNK2_ID, 206 207 }; 207 208 fwrite(&header, sizeof(header), 1, rec.file); 208 record(&rec, sampling_rate, sample_size, channels, sign);209 record(&rec, sampling_rate, channels, format); 209 210 fclose(rec.file); 210 211 -
uspace/app/drec/wave.c
r94694a4 r346643c 40 40 41 41 int wav_parse_header(void *file, const void **data, size_t *data_size, 42 unsigned * sampling_rate, unsigned *sample_size, unsigned *channels,43 bool *sign,const char **error)42 unsigned *channels, unsigned *sampling_rate, pcm_sample_format_t *format, 43 const char **error) 44 44 { 45 45 if (!file) { … … 86 86 } 87 87 88 88 89 if (data) 89 90 *data = header->data; … … 93 94 if (sampling_rate) 94 95 *sampling_rate = uint32_t_le2host(header->sampling_rate); 95 if (sample_size)96 *sample_size = uint32_t_le2host(header->sample_size);97 96 if (channels) 98 97 *channels = uint16_t_le2host(header->channels); 99 if (sign) 100 *sign = uint32_t_le2host(header->sample_size) == 16 101 ? true : false; 98 if (format) { 99 const unsigned size = uint32_t_le2host(header->sample_size); 100 switch (size) { 101 case 8: *format = PCM_SAMPLE_UINT8; break; 102 case 16: *format = PCM_SAMPLE_SINT16_LE; break; 103 case 24: *format = PCM_SAMPLE_SINT24_LE; break; 104 case 32: *format = PCM_SAMPLE_SINT32_LE; break; 105 default: 106 *error = "Unknown format"; 107 return ENOTSUP; 108 } 109 } 102 110 if (error) 103 111 *error = "no error"; -
uspace/app/drec/wave.h
r94694a4 r346643c 37 37 #include <stdint.h> 38 38 #include <bool.h> 39 #include <pcm_sample_format.h> 39 40 40 41 /** Wave file header format. … … 90 91 91 92 int wav_parse_header(void *, const void**, size_t *, unsigned *, unsigned *, 92 unsigned *, bool *, const char **error_str);93 pcm_sample_format_t *, const char **); 93 94 94 95 #endif
Note:
See TracChangeset
for help on using the changeset viewer.