mirror of https://github.com/bjornbytes/lovr.git
48khz sample rate; fixes;
This commit is contained in:
parent
93ea56155e
commit
177a94738d
|
@ -309,7 +309,7 @@ target_link_libraries(lovr
|
|||
if(LOVR_ENABLE_AUDIO)
|
||||
target_sources(lovr PRIVATE
|
||||
src/modules/audio/audio.c
|
||||
src/modules/audio/spatializers/dummy_spatializer.c
|
||||
src/modules/audio/spatializers/simple_spatializer.c
|
||||
src/api/l_audio.c
|
||||
src/api/l_audio_source.c
|
||||
src/lib/miniaudio/miniaudio.c
|
||||
|
|
|
@ -43,8 +43,8 @@ static int l_lovrAudioSetDevice(lua_State *L) {
|
|||
AudioType type = luax_checkenum(L, 1, AudioType, "playback");
|
||||
void* id = lua_touserdata(L, 2);
|
||||
size_t size = luax_len(L, 2);
|
||||
uint32_t sampleRate = lua_tointeger(L, 2);
|
||||
SampleFormat format = luax_checkenum(L, 1, SampleFormat, "f32");
|
||||
uint32_t sampleRate = lua_tointeger(L, 3);
|
||||
SampleFormat format = luax_checkenum(L, 4, SampleFormat, "f32");
|
||||
bool success = lovrAudioSetDevice(type, id, size, sampleRate, format);
|
||||
lua_pushboolean(L, success);
|
||||
return 1;
|
||||
|
@ -174,7 +174,7 @@ int luaopen_lovr_audio(lua_State* L) {
|
|||
lua_pop(L, 2);
|
||||
|
||||
if (lovrAudioInit(spatializer)) {
|
||||
lovrAudioSetDevice(AUDIO_PLAYBACK, NULL, 0, 44100, SAMPLE_F32);
|
||||
lovrAudioSetDevice(AUDIO_PLAYBACK, NULL, 0, PLAYBACK_SAMPLE_RATE, SAMPLE_F32);
|
||||
lovrAudioStart(AUDIO_PLAYBACK);
|
||||
luax_atexit(L, lovrAudioDestroy);
|
||||
}
|
||||
|
|
|
@ -66,11 +66,10 @@ static void onPlayback(ma_device* device, void* out, const void* in, uint32_t co
|
|||
state.leftoverFrames -= leftoverFrames;
|
||||
output += leftoverFrames * OUTPUT_CHANNELS;
|
||||
count -= leftoverFrames;
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ma_mutex_lock(&state.lock);
|
||||
|
||||
|
@ -185,7 +184,7 @@ bool lovrAudioInit(const char* spatializer) {
|
|||
SpatializerConfig spatializerConfig = {
|
||||
.maxSourcesHint = MAX_SOURCES,
|
||||
.fixedBuffer = BUFFER_SIZE,
|
||||
.sampleRate = 44100
|
||||
.sampleRate = PLAYBACK_SAMPLE_RATE
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < sizeof(spatializers) / sizeof(spatializers[0]); i++) {
|
||||
|
@ -264,8 +263,8 @@ bool lovrAudioSetDevice(AudioType type, void* id, size_t size, uint32_t sampleRa
|
|||
ma_device_config config;
|
||||
|
||||
if (type == AUDIO_PLAYBACK) {
|
||||
lovrAssert(sampleRate == 44100, "");
|
||||
lovrAssert(format == SAMPLE_F32, "");
|
||||
lovrAssert(sampleRate == PLAYBACK_SAMPLE_RATE, "Playback sample rate must be %d", PLAYBACK_SAMPLE_RATE);
|
||||
lovrAssert(format == SAMPLE_F32, "Playback format must be f32");
|
||||
config = ma_device_config_init(ma_device_type_playback);
|
||||
config.playback.pDeviceID = (ma_device_id*) id;
|
||||
config.playback.format = miniaudioFormats[format];
|
||||
|
@ -280,7 +279,7 @@ bool lovrAudioSetDevice(AudioType type, void* id, size_t size, uint32_t sampleRa
|
|||
}
|
||||
|
||||
config.sampleRate = sampleRate;
|
||||
config.performanceProfile = ma_performance_profile_low_latency;
|
||||
config.periodSizeInFrames = BUFFER_SIZE;
|
||||
config.dataCallback = callbacks[type];
|
||||
|
||||
ma_device_uninit(&state.devices[type]);
|
||||
|
@ -350,7 +349,7 @@ Source* lovrSourceCreate(SoundData* sound, bool spatial) {
|
|||
config.channelsIn = sound->channels;
|
||||
config.channelsOut = outputChannelCountForSource(source);
|
||||
config.sampleRateIn = sound->sampleRate;
|
||||
config.sampleRateOut = 44100;
|
||||
config.sampleRateOut = PLAYBACK_SAMPLE_RATE;
|
||||
|
||||
ma_data_converter* converter = malloc(sizeof(ma_data_converter));
|
||||
ma_result converterStatus = ma_data_converter_init(&config, converter);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define PLAYBACK_SAMPLE_RATE 48000
|
||||
|
||||
struct SoundData;
|
||||
|
||||
typedef struct Source Source;
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package org.lovr.app;
|
||||
import android.app.NativeActivity;
|
||||
import android.Manifest;
|
||||
import android.app.NativeActivity;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
public class Activity extends NativeActivity {
|
||||
static {
|
||||
|
@ -12,12 +9,6 @@ public class Activity extends NativeActivity {
|
|||
System.loadLibrary("vrapi");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.i("LOVR", "MainActivity.onCreate()");
|
||||
}
|
||||
|
||||
protected native void lovrPermissionEvent(int permission, boolean granted);
|
||||
|
||||
@Override
|
||||
|
@ -25,12 +16,10 @@ public class Activity extends NativeActivity {
|
|||
{
|
||||
if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
Log.i("LOVR", "RECORD_AUDIO granted.");
|
||||
lovrPermissionEvent(0, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.i("LOVR", "RECORD_AUDIO rejected.");
|
||||
lovrPermissionEvent(0, false);
|
||||
}
|
||||
}
|
||||
|
@ -40,12 +29,10 @@ public class Activity extends NativeActivity {
|
|||
int existingPermission = checkSelfPermission(Manifest.permission.RECORD_AUDIO);
|
||||
if(existingPermission != PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
Log.i("LOVR", "Asking for RECORD_AUDIO permissions.");
|
||||
requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.i("LOVR", "RECORD_AUDIO already permitted.");
|
||||
lovrPermissionEvent(0, true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue