mirror of https://github.com/bjornbytes/lovr.git
Single-translation-unit experiment;
This commit is contained in:
parent
1aef9963f5
commit
6f7c30e7e2
|
@ -361,8 +361,6 @@ if(LOVR_ENABLE_AUDIO)
|
|||
add_definitions(-DLOVR_ENABLE_AUDIO)
|
||||
target_sources(lovr PRIVATE
|
||||
src/audio/audio.c
|
||||
src/audio/microphone.c
|
||||
src/audio/source.c
|
||||
src/api/audio.c
|
||||
src/api/types/source.c
|
||||
src/api/types/microphone.c
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
#include <AL/alc.h>
|
||||
#include <AL/alext.h>
|
||||
|
||||
#include "microphone.c"
|
||||
#include "source.c"
|
||||
|
||||
static struct {
|
||||
bool initialized;
|
||||
ALCdevice* device;
|
||||
|
@ -76,7 +79,7 @@ void lovrAudioDestroy() {
|
|||
void lovrAudioUpdate() {
|
||||
int i; Source* source;
|
||||
vec_foreach_rev(&state.sources, source, i) {
|
||||
if (source->type == SOURCE_STATIC) {
|
||||
if (lovrSourceGetType(source) == SOURCE_STATIC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,23 @@
|
|||
#include "audio/microphone.h"
|
||||
#include "audio/audio.h"
|
||||
#include "data/soundData.h"
|
||||
#include "types.h"
|
||||
#include "util.h"
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
|
||||
Microphone* lovrMicrophoneInit(Microphone* microphone, const char* name, size_t samples, uint32_t sampleRate, uint32_t bitDepth, uint32_t channelCount) {
|
||||
struct Microphone {
|
||||
Ref ref;
|
||||
ALCdevice* device;
|
||||
const char* name;
|
||||
bool isRecording;
|
||||
uint32_t sampleRate;
|
||||
uint32_t bitDepth;
|
||||
uint32_t channelCount;
|
||||
};
|
||||
|
||||
Microphone* lovrMicrophoneCreate(const char* name, size_t samples, uint32_t sampleRate, uint32_t bitDepth, uint32_t channelCount) {
|
||||
Microphone* microphone = lovrAlloc(Microphone);
|
||||
ALCdevice* device = alcCaptureOpenDevice(name, sampleRate, lovrAudioConvertFormat(bitDepth, channelCount), samples);
|
||||
lovrAssert(device, "Error opening capture device for microphone '%s'", name);
|
||||
microphone->device = device;
|
||||
|
|
|
@ -1,25 +1,13 @@
|
|||
#include "types.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
struct SoundData;
|
||||
|
||||
typedef struct Microphone {
|
||||
Ref ref;
|
||||
ALCdevice* device;
|
||||
const char* name;
|
||||
bool isRecording;
|
||||
uint32_t sampleRate;
|
||||
uint32_t bitDepth;
|
||||
uint32_t channelCount;
|
||||
} Microphone;
|
||||
|
||||
Microphone* lovrMicrophoneInit(Microphone* microphone, const char* name, size_t samples, uint32_t sampleRate, uint32_t bitDepth, uint32_t channelCount);
|
||||
#define lovrMicrophoneCreate(...) lovrMicrophoneInit(lovrAlloc(Microphone), __VA_ARGS__)
|
||||
typedef struct Microphone Microphone;
|
||||
Microphone* lovrMicrophoneCreate(const char* name, size_t samples, uint32_t sampleRate, uint32_t bitDepth, uint32_t channelCount);
|
||||
void lovrMicrophoneDestroy(void* ref);
|
||||
uint32_t lovrMicrophoneGetBitDepth(Microphone* microphone);
|
||||
uint32_t lovrMicrophoneGetChannelCount(Microphone* microphone);
|
||||
|
|
|
@ -3,8 +3,23 @@
|
|||
#include "data/audioStream.h"
|
||||
#include "data/soundData.h"
|
||||
#include "lib/maf.h"
|
||||
#include "types.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
|
||||
#define SOURCE_BUFFERS 4
|
||||
|
||||
struct Source {
|
||||
Ref ref;
|
||||
SourceType type;
|
||||
struct SoundData* soundData;
|
||||
struct AudioStream* stream;
|
||||
ALuint id;
|
||||
ALuint buffers[SOURCE_BUFFERS];
|
||||
bool isLooping;
|
||||
};
|
||||
|
||||
static ALenum lovrSourceGetState(Source* source) {
|
||||
ALenum state;
|
||||
|
@ -12,7 +27,8 @@ static ALenum lovrSourceGetState(Source* source) {
|
|||
return state;
|
||||
}
|
||||
|
||||
Source* lovrSourceInitStatic(Source* source, SoundData* soundData) {
|
||||
Source* lovrSourceCreateStatic(SoundData* soundData) {
|
||||
Source* source = lovrAlloc(Source);
|
||||
ALenum format = lovrAudioConvertFormat(soundData->bitDepth, soundData->channelCount);
|
||||
source->type = SOURCE_STATIC;
|
||||
source->soundData = soundData;
|
||||
|
@ -24,7 +40,8 @@ Source* lovrSourceInitStatic(Source* source, SoundData* soundData) {
|
|||
return source;
|
||||
}
|
||||
|
||||
Source* lovrSourceInitStream(Source* source, AudioStream* stream) {
|
||||
Source* lovrSourceCreateStream(AudioStream* stream) {
|
||||
Source* source = lovrAlloc(Source);
|
||||
source->type = SOURCE_STREAM;
|
||||
source->stream = stream;
|
||||
alGenSources(1, &source->id);
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
#include "types.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -22,20 +19,9 @@ typedef enum {
|
|||
UNIT_SAMPLES
|
||||
} TimeUnit;
|
||||
|
||||
typedef struct Source {
|
||||
Ref ref;
|
||||
SourceType type;
|
||||
struct SoundData* soundData;
|
||||
struct AudioStream* stream;
|
||||
ALuint id;
|
||||
ALuint buffers[SOURCE_BUFFERS];
|
||||
bool isLooping;
|
||||
} Source;
|
||||
|
||||
Source* lovrSourceInitStatic(Source* source, struct SoundData* soundData);
|
||||
Source* lovrSourceInitStream(Source* source, struct AudioStream* stream);
|
||||
#define lovrSourceCreateStatic(...) lovrSourceInitStatic(lovrAlloc(Source), __VA_ARGS__)
|
||||
#define lovrSourceCreateStream(...) lovrSourceInitStream(lovrAlloc(Source), __VA_ARGS__)
|
||||
typedef struct Source Source;
|
||||
Source* lovrSourceCreateStatic(struct SoundData* soundData);
|
||||
Source* lovrSourceCreateStream(struct AudioStream* stream);
|
||||
void lovrSourceDestroy(void* ref);
|
||||
SourceType lovrSourceGetType(Source* source);
|
||||
uint32_t lovrSourceGetBitDepth(Source* source);
|
||||
|
|
Loading…
Reference in New Issue