Creates a sound data resource (.oggc/.opusc/.wavc) * * Creates a sound data resource * Supported formats are .oggc, .opusc and .wavc * * @name resource.create_sound_data * @param path [type:string] the path to the resource. Must not already exist. * @param [options] [type:table] A table containing parameters for the text. Supported entries: * * `data` * : [type:string] The raw data of th
| 2988 | * ``` |
| 2989 | */ |
| 2990 | static int CreateSoundData(lua_State* L) |
| 2991 | { |
| 2992 | DM_LUA_STACK_CHECK(L, 1); |
| 2993 | |
| 2994 | const char* path = luaL_checkstring(L, 1); |
| 2995 | const char* path_ext = dmResource::GetExtFromPath(path); |
| 2996 | |
| 2997 | const char* exts[] = {"wav", "ogg", "opus", "wavc", "oggc", "opusc"}; |
| 2998 | |
| 2999 | dmhash_t canonical_path_hash = 0; |
| 3000 | PreCreateResources(L, path, exts, DM_ARRAY_SIZE(exts), &canonical_path_hash); |
| 3001 | |
| 3002 | // Find the correct type, as the resource types are registered as .wavc / .oggc / .opusc |
| 3003 | char type_suffix[32]; |
| 3004 | { |
| 3005 | int len = dmStrlCpy(type_suffix, path_ext, sizeof(type_suffix)); |
| 3006 | if (type_suffix[len-1] != 'c') |
| 3007 | { |
| 3008 | type_suffix[len++] = 'c'; |
| 3009 | type_suffix[len] = 0; |
| 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | dmResource::HResourceType resource_type; |
| 3014 | dmResource::Result r = dmResource::GetTypeFromExtension(g_ResourceModule.m_Factory, type_suffix, &resource_type); |
| 3015 | if (dmResource::RESULT_OK != r) |
| 3016 | { |
| 3017 | return luaL_error(L, "Failed to find resource type '%s': %s %d", type_suffix, dmResource::ResultToString(r), r); |
| 3018 | } |
| 3019 | |
| 3020 | ////////////////////////////////////////////////// |
| 3021 | // Options table |
| 3022 | luaL_checktype(L, 2, LUA_TTABLE); |
| 3023 | lua_pushvalue(L, 2); |
| 3024 | |
| 3025 | uint32_t data_size = 0; |
| 3026 | uint8_t* data = 0; |
| 3027 | |
| 3028 | lua_getfield(L, -1, "data"); |
| 3029 | data = CheckBufferOrString(L, -1, &data_size); |
| 3030 | lua_pop(L, 1); // "data" |
| 3031 | |
| 3032 | uint32_t file_size = data_size; |
| 3033 | bool partial = CheckFieldValue<bool>(L, -1, "partial", false); |
| 3034 | if (partial) |
| 3035 | { |
| 3036 | file_size = CheckFieldValue<int>(L, -1, "filesize"); |
| 3037 | } |
| 3038 | |
| 3039 | lua_pop(L, 1); // args table |
| 3040 | // End options table |
| 3041 | ////////////////////////////////////////////////// |
| 3042 | |
| 3043 | void* resource = 0x0; |
| 3044 | dmResource::Result res = dmResource::CreateResourcePartial(g_ResourceModule.m_Factory, resource_type, path, data, data_size, file_size, &resource); |
| 3045 | |
| 3046 | if (res != dmResource::RESULT_OK) |
| 3047 | { |
nothing calls this directly
no test coverage detected