Changeset 4bec78f in mainline
- Timestamp:
- 2012-07-05T20:48:10Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 124f9bd
- Parents:
- 725d038
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dplay/dplay.c
r725d038 r4bec78f 50 50 51 51 #define DEFAULT_DEVICE "/hw/pci0/00:01.0/sb16/dsp" 52 53 static void play(async_exch_t *device, unsigned buffer_id, 54 void *buffer, size_t size, FILE *source, 52 #define SUBBUFFERS 4 53 54 typedef struct { 55 struct { 56 void *base; 57 size_t size; 58 unsigned id; 59 void* position; 60 } buffer; 61 FILE* source; 62 } playback_t; 63 64 65 static void device_event_callback(ipc_callid_t id, ipc_call_t *call, void* arg) 66 { 67 if (IPC_GET_IMETHOD(*call) != IPC_FIRST_USER_METHOD) { 68 printf("Unknown event.\n"); 69 return; 70 } 71 playback_t *pb = arg; 72 printf("Got device event!!!\n"); 73 const size_t buffer_part = pb->buffer.size / SUBBUFFERS; 74 const size_t bytes = fread(pb->buffer.position, sizeof(uint8_t), 75 buffer_part, pb->source); 76 if (bytes == 0) 77 exit(0); // ugly but temporary 78 pb->buffer.position += bytes; 79 if (bytes != buffer_part) 80 bzero(pb->buffer.position, buffer_part - bytes); 81 pb->buffer.position += buffer_part - bytes; 82 if (pb->buffer.position >= (pb->buffer.base + pb->buffer.size)) 83 pb->buffer.position = pb->buffer.base; 84 } 85 86 87 static void play(async_exch_t *device, playback_t *pb, 55 88 unsigned sampling_rate, unsigned sample_size, unsigned channels, bool sign) 56 89 { 57 90 assert(device); 58 const size_t update_size = size / 8; 91 assert(pb); 92 pb->buffer.position = pb->buffer.base; 93 printf("Playing: %dHz, %d-bit samples, %d channel(s), %sSIGNED.\n", 94 sampling_rate, sample_size, channels, sign ? "": "UN"); 95 const size_t bytes = fread(pb->buffer.base, sizeof(uint8_t), 96 pb->buffer.size, pb->source); 97 if (bytes != pb->buffer.size) 98 return; 99 printf("Buffer data ready.\n"); 100 sleep(10); 101 #if 0 102 const size_t update_size = size / SUBBUFFERS; 59 103 60 104 /* Time to play half the buffer. */ … … 70 114 gettimeofday(&time, NULL); 71 115 printf("Starting playback.\n"); 72 int ret = audio_pcm_buffer_start_playback(device, buffer_id, 116 int ret = audio_pcm_buffer_start_playback(device, buffer_id, SUBBUFFERS, 73 117 sampling_rate, sample_size, channels, sign); 74 118 if (ret != EOK) { … … 85 129 const suseconds_t delay = min(tv_sub(&time, ¤t), interval); 86 130 if (delay > 0) 87 u sleep(delay);131 udelay(delay); 88 132 89 133 const size_t bytes = … … 106 150 printf("Failed to stop playback: %s.\n", str_error(ret)); 107 151 } 152 #endif 108 153 } 109 154 … … 134 179 135 180 async_sess_t *session = devman_device_connect( 136 EXCHANGE_ ATOMIC, pcm_handle, IPC_FLAG_BLOCKING);181 EXCHANGE_SERIALIZE, pcm_handle, IPC_FLAG_BLOCKING); 137 182 if (!session) { 138 183 printf("Failed to connect to device.\n"); … … 146 191 return 1; 147 192 } 148 const char* info ;193 const char* info = NULL; 149 194 ret = audio_pcm_buffer_get_info_str(exch, &info); 150 195 if (ret != EOK) { … … 157 202 free(info); 158 203 159 void *buffer = NULL; 160 size_t size = 0; 161 unsigned id = 0; 162 ret = audio_pcm_buffer_get_buffer(exch, &buffer, &size, &id); 204 playback_t pb = {{0}, NULL}; 205 pb.buffer.size = 4096; 206 printf("Requesting buffer: %p, %zu, %u.\n", pb.buffer.base, pb.buffer.size, pb.buffer.id); 207 ret = audio_pcm_buffer_get_buffer(exch, &pb.buffer.base, 208 &pb.buffer.size, &pb.buffer.id, device_event_callback, &pb); 163 209 if (ret != EOK) { 164 210 printf("Failed to get PCM buffer: %s.\n", str_error(ret)); … … 167 213 return 1; 168 214 } 169 printf("Buffer (%u): %p %zu.\n", id, buffer, size); 170 171 FILE *source = fopen(file, "rb"); 172 if (source == NULL) { 215 printf("Buffer (%u): %p %zu.\n", pb.buffer.id, pb.buffer.base, 216 pb.buffer.size); 217 218 pb.source = fopen(file, "rb"); 219 if (pb.source == NULL) { 173 220 printf("Failed to open %s.\n", file); 174 munmap( buffer,size);175 audio_pcm_buffer_release_buffer(exch, id);221 munmap(pb.buffer.base, pb.buffer.size); 222 audio_pcm_buffer_release_buffer(exch, pb.buffer.id); 176 223 async_exchange_end(exch); 177 224 async_hangup(session); … … 179 226 } 180 227 wave_header_t header; 181 fread(&header, sizeof(header), 1, source);228 fread(&header, sizeof(header), 1, pb.source); 182 229 unsigned rate, sample_size, channels; 183 230 bool sign; … … 187 234 if (ret != EOK) { 188 235 printf("Error parsing wav header: %s.\n", error); 189 fclose( source);190 munmap( buffer,size);191 audio_pcm_buffer_release_buffer(exch, id);192 async_exchange_end(exch); 193 async_hangup(session); 194 return 1; 195 } 196 197 play(exch, id, buffer, size, source, rate, sample_size, channels, sign);198 199 munmap( buffer,size);200 audio_pcm_buffer_release_buffer(exch, id);236 fclose(pb.source); 237 munmap(pb.buffer.base, pb.buffer.size); 238 audio_pcm_buffer_release_buffer(exch, pb.buffer.id); 239 async_exchange_end(exch); 240 async_hangup(session); 241 return 1; 242 } 243 244 play(exch, &pb, rate, sample_size, channels, sign); 245 246 munmap(pb.buffer.base, pb.buffer.size); 247 audio_pcm_buffer_release_buffer(exch, pb.buffer.id); 201 248 async_exchange_end(exch); 202 249 async_hangup(session);
Note:
See TracChangeset
for help on using the changeset viewer.