diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-25 08:34:30 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-04-25 08:34:30 +0300 |
commit | d57240fea98543eb5b0394a3e01268ee2e08b6ec (patch) | |
tree | 54081d3590753a2dcf081464c0ea6c2dcdff954e | |
parent | 6497df3c6c9f9344db516751ee3c8732d4cfaf38 (diff) |
iOS: Fixed audio issues
Fighting with ARC, and increased the audio sample buffer size to reduce wakeups.
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/audio/player.c | 2 | ||||
-rw-r--r-- | src/ios.m | 25 |
3 files changed, 16 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 32805172..9ef71960 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -22,7 +22,7 @@ project (Lagrange | |||
22 | DESCRIPTION "A Beautiful Gemini Client" | 22 | DESCRIPTION "A Beautiful Gemini Client" |
23 | LANGUAGES C | 23 | LANGUAGES C |
24 | ) | 24 | ) |
25 | set (IOS_BUNDLE_VERSION 4) | 25 | set (IOS_BUNDLE_VERSION 6) |
26 | set (COPYRIGHT_YEAR 2021) | 26 | set (COPYRIGHT_YEAR 2021) |
27 | 27 | ||
28 | # Build configuration. | 28 | # Build configuration. |
diff --git a/src/audio/player.c b/src/audio/player.c index 20b40f73..9e026561 100644 --- a/src/audio/player.c +++ b/src/audio/player.c | |||
@@ -617,7 +617,7 @@ static iContentSpec contentSpec_Player_(const iPlayer *d) { | |||
617 | iAssert(content.inputFormat == content.output.format || | 617 | iAssert(content.inputFormat == content.output.format || |
618 | (content.inputFormat == AUDIO_S24LSB && content.output.format == AUDIO_S16) || | 618 | (content.inputFormat == AUDIO_S24LSB && content.output.format == AUDIO_S16) || |
619 | (content.inputFormat == AUDIO_F64LSB && content.output.format == AUDIO_F32)); | 619 | (content.inputFormat == AUDIO_F64LSB && content.output.format == AUDIO_F32)); |
620 | content.output.samples = 2048; | 620 | content.output.samples = 8192; |
621 | return content; | 621 | return content; |
622 | } | 622 | } |
623 | 623 | ||
@@ -327,7 +327,7 @@ enum iAVFAudioPlayerState { | |||
327 | 327 | ||
328 | struct Impl_AVFAudioPlayer { | 328 | struct 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 | |||
365 | iBool setInput_AVFAudioPlayer(iAVFAudioPlayer *d, const iString *mimeType, const iBlock *audioFileData) { | 367 | iBool 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 | ||
394 | void play_AVFAudioPlayer(iAVFAudioPlayer *d) { | 397 | void 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 | ||
401 | void stop_AVFAudioPlayer(iAVFAudioPlayer *d) { | 404 | void 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 | ||
406 | void setPaused_AVFAudioPlayer(iAVFAudioPlayer *d, iBool paused) { | 409 | void 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) { | |||
417 | void setVolume_AVFAudioPlayer(iAVFAudioPlayer *d, float volume) { | 420 | void 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 | ||
424 | double currentTime_AVFAudioPlayer(const iAVFAudioPlayer *d) { | 427 | double currentTime_AVFAudioPlayer(const iAVFAudioPlayer *d) { |
425 | return [d->player currentTime]; | 428 | return [REF_d_player currentTime]; |
426 | } | 429 | } |
427 | 430 | ||
428 | double duration_AVFAudioPlayer(const iAVFAudioPlayer *d) { | 431 | double duration_AVFAudioPlayer(const iAVFAudioPlayer *d) { |
429 | return [d->player duration]; | 432 | return [REF_d_player duration]; |
430 | } | 433 | } |
431 | 434 | ||
432 | iBool isStarted_AVFAudioPlayer(const iAVFAudioPlayer *d) { | 435 | iBool isStarted_AVFAudioPlayer(const iAVFAudioPlayer *d) { |