Skip to content

Commit

Permalink
- more os and music apis for ios app dev
Browse files Browse the repository at this point in the history
  • Loading branch information
polymonster committed Jan 19, 2024
1 parent aed16ce commit c684c82
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
2 changes: 2 additions & 0 deletions core/pen/include/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace pen
Str os_get_persistent_data_directory();
Str os_get_cache_data_directory();
void os_create_directory(const Str& dir);
bool os_delete_directory(const Str& filename);
void os_open_url(const Str& url);
void os_ignore_slient();
void os_enable_background_audio();
Expand Down Expand Up @@ -74,5 +75,6 @@ namespace pen
void music_enable_remote_control();
void music_set_now_playing(const Str& artist, const Str& album, const Str& track);
void music_set_now_playing_artwork(void* data, u32 w, u32 h, u32 bpp, u32 row_pitch);
void music_set_now_playing_position();

} // namespace pen
14 changes: 14 additions & 0 deletions core/pen/source/ios/os.mm
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ void os_create_directory(const Str& dir)
}
}

bool os_delete_directory(const Str& filename)
{
bool ret = false;
@autoreleasepool {
NSFileManager* manager = [NSFileManager defaultManager];
ret = [manager removeItemAtPath:[NSString stringWithUTF8String:filename.c_str()] error:nil];
}
return ret;
}

void os_open_url(const Str& url)
{
@autoreleasepool {
Expand Down Expand Up @@ -510,4 +520,8 @@ void music_set_now_playing_artwork(void* data, u32 w, u32 h, u32 bpp, u32 row_pi
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mut_info];
}
}

void music_set_now_playing_position() {

}
}
3 changes: 2 additions & 1 deletion core/put/source/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ namespace put

struct audio_sound_file_info
{
u32 length_ms;
u32 error = 0;
u32 length_ms = 0;
};

struct audio_channel_state
Expand Down
55 changes: 34 additions & 21 deletions core/put/source/audio/audio_fmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ namespace

struct audio_resource_allocation
{
void* resource;
u32 num_dsp = 0;

void* resource;
u32 num_dsp = 0;
audio_resource_type type;

std::atomic<u8> assigned_flag;
std::atomic<u8> assigned_flag;
};

struct resource_state
Expand Down Expand Up @@ -270,13 +268,14 @@ namespace put
FMOD_RESULT result = _sound_system->createSound(resovled_name.c_str(), FMOD_DEFAULT, NULL,
(FMOD::Sound**)&_audio_resources[resource_slot].resource);

PEN_ASSERT(result == FMOD_OK);

// populate sound info
FMOD::Sound* new_sound = (FMOD::Sound*)_audio_resources[resource_slot].resource;

new_sound->getLength(&_sound_file_info[resource_slot].length_ms, FMOD_TIMEUNIT_MS);

_sound_file_info[resource_slot].error = result;
if(result == FMOD_OK)
{
FMOD::Sound* new_sound = (FMOD::Sound*)_audio_resources[resource_slot].resource;
FMOD_RESULT ms_result = new_sound->getLength(&_sound_file_info[resource_slot].length_ms, FMOD_TIMEUNIT_MS);
PEN_LOG("FMOD TIMEMS %i", ms_result);
}
_sound_file_info_ready[resource_slot] = true;

return resource_slot;
Expand All @@ -301,11 +300,15 @@ namespace put

FMOD_RESULT result = _sound_system->createSound((const char*)music.pcm_data, FMOD_OPENRAW | FMOD_OPENMEMORY_POINT,
&exinfo, (FMOD::Sound**)&_audio_resources[resource_slot].resource);
PEN_ASSERT(result == FMOD_OK);


// populate sound info
FMOD::Sound* new_sound = (FMOD::Sound*)_audio_resources[resource_slot].resource;
new_sound->getLength(&_sound_file_info[resource_slot].length_ms, FMOD_TIMEUNIT_MS);
_sound_file_info[resource_slot].error = result;
if(result == FMOD_OK)
{
FMOD::Sound* new_sound = (FMOD::Sound*)_audio_resources[resource_slot].resource;
FMOD_RESULT ms_result = new_sound->getLength(&_sound_file_info[resource_slot].length_ms, FMOD_TIMEUNIT_MS);
PEN_LOG("FMOD TIMEMS %i", ms_result);
}
_sound_file_info_ready[resource_slot] = true;

return resource_slot;
Expand All @@ -320,10 +323,22 @@ namespace put
_audio_resources[resource_slot].assigned_flag |= 0xff;
_audio_resources[resource_slot].type = AUDIO_RESOURCE_SOUND;

FMOD_RESULT result = _sound_system->createStream(filename, FMOD_LOOP_NORMAL | FMOD_2D, 0,
(FMOD::Sound**)&_audio_resources[resource_slot].resource);

PEN_ASSERT(result == FMOD_OK);
FMOD_RESULT result = _sound_system->createStream(
filename,
FMOD_LOOP_OFF | FMOD_2D | FMOD_IGNORETAGS | FMOD_MPEGSEARCH,
0,
(FMOD::Sound**)&_audio_resources[resource_slot].resource
);

// populate sound info
_sound_file_info[resource_slot].error = result;
if(result == FMOD_OK)
{
FMOD::Sound* new_sound = (FMOD::Sound*)_audio_resources[resource_slot].resource;
FMOD_RESULT ms_result = new_sound->getLength(&_sound_file_info[resource_slot].length_ms, FMOD_TIMEUNIT_MS);
PEN_LOG("FMOD TIMEMS %i", ms_result);
}
_sound_file_info_ready[resource_slot] = true;

return resource_slot;
}
Expand Down Expand Up @@ -360,8 +375,6 @@ namespace put
result = _sound_system->playSound((FMOD::Sound*)_audio_resources[sound_index].resource, 0, false,
(FMOD::Channel**)&_audio_resources[resource_slot].resource);

PEN_ASSERT(result == FMOD_OK);

return resource_slot;
}

Expand Down

0 comments on commit c684c82

Please sign in to comment.