summaryrefslogtreecommitdiff
path: root/src/ios.m
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-04-25 08:34:30 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-04-25 08:34:30 +0300
commitd57240fea98543eb5b0394a3e01268ee2e08b6ec (patch)
tree54081d3590753a2dcf081464c0ea6c2dcdff954e /src/ios.m
parent6497df3c6c9f9344db516751ee3c8732d4cfaf38 (diff)
iOS: Fixed audio issues
Fighting with ARC, and increased the audio sample buffer size to reduce wakeups.
Diffstat (limited to 'src/ios.m')
-rw-r--r--src/ios.m25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/ios.m b/src/ios.m
index ccf395fb..6e2fa64b 100644
--- a/src/ios.m
+++ b/src/ios.m
@@ -327,7 +327,7 @@ enum iAVFAudioPlayerState {
327 327
328struct Impl_AVFAudioPlayer { 328struct Impl_AVFAudioPlayer {
329 iString cacheFilePath; 329 iString cacheFilePath;
330 AVAudioPlayer *player; 330 void *player; /* AVAudioPlayer *, no ARC */
331 float volume; 331 float volume;
332 enum iAVFAudioPlayerState state; 332 enum iAVFAudioPlayerState state;
333}; 333};
@@ -362,12 +362,15 @@ static const char *fileExt_(const iString *mimeType) {
362 return ""; 362 return "";
363} 363}
364 364
365#define REF_d_player (__bridge AVAudioPlayer *)d->player
366
365iBool setInput_AVFAudioPlayer(iAVFAudioPlayer *d, const iString *mimeType, const iBlock *audioFileData) { 367iBool setInput_AVFAudioPlayer(iAVFAudioPlayer *d, const iString *mimeType, const iBlock *audioFileData) {
366 if (!isEmpty_String(&d->cacheFilePath)) { 368 if (!isEmpty_String(&d->cacheFilePath)) {
367 remove(cstr_String(&d->cacheFilePath)); 369 remove(cstr_String(&d->cacheFilePath));
368 clear_String(&d->cacheFilePath); 370 clear_String(&d->cacheFilePath);
369 } 371 }
370 if (d->player) { 372 if (d->player) {
373 CFBridgingRelease(d->player);
371 d->player = nil; 374 d->player = nil;
372 } 375 }
373 if (mimeType && audioFileData && iCmpStr(fileExt_(mimeType), "")) { 376 if (mimeType && audioFileData && iCmpStr(fileExt_(mimeType), "")) {
@@ -377,14 +380,14 @@ iBool setInput_AVFAudioPlayer(iAVFAudioPlayer *d, const iString *mimeType, const
377 write_File(f, audioFileData); 380 write_File(f, audioFileData);
378 set_String(&d->cacheFilePath, path_File(f)); 381 set_String(&d->cacheFilePath, path_File(f));
379 NSError *error = nil; 382 NSError *error = nil;
380 d->player = [[AVAudioPlayer alloc] 383 d->player = (void *) CFBridgingRetain([[AVAudioPlayer alloc]
381 initWithContentsOfURL:[NSURL fileURLWithPath: 384 initWithContentsOfURL:[NSURL fileURLWithPath:
382 [NSString stringWithUTF8String:cstr_String(&d->cacheFilePath)]] 385 [NSString stringWithUTF8String:cstr_String(&d->cacheFilePath)]]
383 error:&error]; 386 error:&error]);
384 if (error) { 387 if (error) {
385 d->player = nil; 388 d->player = nil;
386 } 389 }
387 [d->player setVolume:d->volume]; 390 [REF_d_player setVolume:d->volume];
388 } 391 }
389 iRelease(f); 392 iRelease(f);
390 } 393 }
@@ -393,23 +396,23 @@ iBool setInput_AVFAudioPlayer(iAVFAudioPlayer *d, const iString *mimeType, const
393 396
394void play_AVFAudioPlayer(iAVFAudioPlayer *d) { 397void play_AVFAudioPlayer(iAVFAudioPlayer *d) {
395 if (d->state != playing_AVFAudioPlayerState) { 398 if (d->state != playing_AVFAudioPlayerState) {
396 [d->player play]; 399 [REF_d_player play];
397 d->state = playing_AVFAudioPlayerState; 400 d->state = playing_AVFAudioPlayerState;
398 } 401 }
399} 402}
400 403
401void stop_AVFAudioPlayer(iAVFAudioPlayer *d) { 404void stop_AVFAudioPlayer(iAVFAudioPlayer *d) {
402 [d->player stop]; 405 [REF_d_player stop];
403 d->state = initialized_AVFAudioPlayerState; 406 d->state = initialized_AVFAudioPlayerState;
404} 407}
405 408
406void setPaused_AVFAudioPlayer(iAVFAudioPlayer *d, iBool paused) { 409void setPaused_AVFAudioPlayer(iAVFAudioPlayer *d, iBool paused) {
407 if (paused && d->state != paused_AVFAudioPlayerState) { 410 if (paused && d->state != paused_AVFAudioPlayerState) {
408 [d->player pause]; 411 [REF_d_player pause];
409 d->state = paused_AVFAudioPlayerState; 412 d->state = paused_AVFAudioPlayerState;
410 } 413 }
411 else if (!paused && d->state != playing_AVFAudioPlayerState) { 414 else if (!paused && d->state != playing_AVFAudioPlayerState) {
412 [d->player play]; 415 [REF_d_player play];
413 d->state = playing_AVFAudioPlayerState; 416 d->state = playing_AVFAudioPlayerState;
414 } 417 }
415} 418}
@@ -417,16 +420,16 @@ void setPaused_AVFAudioPlayer(iAVFAudioPlayer *d, iBool paused) {
417void setVolume_AVFAudioPlayer(iAVFAudioPlayer *d, float volume) { 420void setVolume_AVFAudioPlayer(iAVFAudioPlayer *d, float volume) {
418 d->volume = volume; 421 d->volume = volume;
419 if (d->player) { 422 if (d->player) {
420 [d->player setVolume:volume]; 423 [REF_d_player setVolume:volume];
421 } 424 }
422} 425}
423 426
424double currentTime_AVFAudioPlayer(const iAVFAudioPlayer *d) { 427double currentTime_AVFAudioPlayer(const iAVFAudioPlayer *d) {
425 return [d->player currentTime]; 428 return [REF_d_player currentTime];
426} 429}
427 430
428double duration_AVFAudioPlayer(const iAVFAudioPlayer *d) { 431double duration_AVFAudioPlayer(const iAVFAudioPlayer *d) {
429 return [d->player duration]; 432 return [REF_d_player duration];
430} 433}
431 434
432iBool isStarted_AVFAudioPlayer(const iAVFAudioPlayer *d) { 435iBool isStarted_AVFAudioPlayer(const iAVFAudioPlayer *d) {