OSDN Git Service

Add the start of the OSS backend
authorAlaskanEmily <yoloshart@gmail.com>
Sun, 27 May 2018 21:24:09 +0000 (14:24 -0700)
committerAlaskanEmily <yoloshart@gmail.com>
Sun, 27 May 2018 21:24:09 +0000 (14:24 -0700)
oss/cin_driver_oss.cpp [new file with mode: 0755]
oss/cin_driver_oss.hpp [new file with mode: 0755]
oss/cin_sound_oss.c [new file with mode: 0755]
oss/cin_sound_oss.h [new file with mode: 0755]

diff --git a/oss/cin_driver_oss.cpp b/oss/cin_driver_oss.cpp
new file mode 100755 (executable)
index 0000000..c6200df
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018 AlaskanEmily
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "cin_driver.h"
+#include "cin_driver_oss.hpp"
+#include "cin_loader.h"
+#include "cin_loader_soft.h"
+
+#include <sys/soundcard.h>
+
+unsigned Cin_StructDriverSize(){
+    return sizeof(struct Cin_Driver);
+}
+
+enum Cin_DriverError Cin_CreateDriver(struct Cin_Driver *drv){
+    new (drv) Cin_Driver();
+    return Cin_eDriverSuccess;
+}
+
+void Cin_DestroyDriver(struct Cin_Driver *drv){
+    drv->~Cin_Driver();
+}
diff --git a/oss/cin_driver_oss.hpp b/oss/cin_driver_oss.hpp
new file mode 100755 (executable)
index 0000000..95b58a9
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 AlaskanEmily
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef CIN_DRIVER_OSS_HPP
+#define CIN_DRIVER_OSS_HPP
+#pragma once
+
+#include "mixer/cin_driver_mixer.hpp"
+
+#include "cin_sound_oss.h"
+
+struct Cin_Driver : public Cin_DriverMixer {
+private:
+
+protected:
+    
+    virtual void signalNewEvents();
+    
+    virtual void run();
+    
+    virtual void remove(const struct Cin_Sound *sound);
+    
+    virtual void add(struct Cin_Sound *sound, uintptr_t event);
+    
+public:
+    
+};
+
+#endif // CIN_DRIVER_OSS_HPP
diff --git a/oss/cin_sound_oss.c b/oss/cin_sound_oss.c
new file mode 100755 (executable)
index 0000000..c07bfad
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2018 AlaskanEmily
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "cin_sound.h"
+#include "cin_sound_oss.h"
+
+#include "cin_loader.h"
+#include "cin_loader_soft.h"
+
+#include "mixer/cin_lock.h"
+#include "mixer/cin_driver_mixer_ops.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+void Cin_OSS_SetSoundState(struct Cin_OSS_SoundTableData *table, int state){
+    Cin_ClaimLock(table->lock);
+    table->table[0][table->offset] = state;
+    Cin_ReleaseLock(table->lock);
+}
+
+enum Cin_LoaderError Cin_LoaderFinalize(struct Cin_Loader *ld,
+    struct Cin_Sound *snd){
+    
+    memcpy(&(snd->state_table_data),
+        ld->data,
+        sizeof(struct Cin_OSS_SoundTableData));
+    free(ld->data);
+    
+    {
+        const unsigned num_bytes = ld->bytes_placed;
+        void *const data = malloc(num_bytes);
+        snd->sound_data.num_bytes = num_bytes;
+        snd->sound_data.samples = data;
+        Cin_LoaderMemcpy(ld->first, 0, data, num_bytes);
+    }
+    
+    snd->sound_data.format.sample_rate = ld->sample_rate;
+    snd->sound_data.format.num_channels = ld->channels;
+    snd->sound_data.format.sample_format = ld->format;
+    Cin_MixerDriverAddSound(snd->state_table_data.mixer, snd, 0);
+    return Cin_eSoundSuccess;
+}
+
+unsigned Cin_StructSoundSize(){
+    return sizeof(struct Cin_Sound);
+}
+
+enum Cin_SoundError Cin_SoundPlay(struct Cin_Sound *snd){
+    Cin_OSS_SetSoundState(&(snd->state_table_data), CIN_OSS_SOUND_PLAY);
+    return Cin_eSoundSuccess;
+}
+
+enum Cin_SoundError Cin_SoundStop(struct Cin_Sound *snd){
+    Cin_OSS_SetSoundState(&(snd->state_table_data), CIN_OSS_SOUND_STOP);
+    return Cin_eSoundSuccess;
+}
+
+void Cin_DestroySound(struct Cin_Sound *snd){
+    Cin_MixerDriverRemoveSound(snd->state_table_data.mixer, snd);
+}
diff --git a/oss/cin_sound_oss.h b/oss/cin_sound_oss.h
new file mode 100755 (executable)
index 0000000..dabaf9f
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2018 AlaskanEmily
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef CIN_SOUND_OSS_H
+#define CIN_SOUND_OSS_H
+#pragma once
+
+#include "dsp/cin_dsp.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Cin_Lock;
+struct Cin_DriverMixer;
+
+#define CIN_OSS_SOUND_STOP 0
+#define CIN_OSS_SOUND_PLAY 1
+
+struct Cin_OSS_SoundTableData {
+    struct Cin_Lock *lock;
+    int **table;
+    unsigned offset;
+    struct Cin_DriverMixer *mixer;
+};
+
+struct Cin_OSS_SoundData{
+    struct Cin_DSP_MixerFormat format;
+    unsigned num_bytes;
+    void *samples;
+};
+
+struct Cin_Sound {
+    struct Cin_OSS_SoundData sound_data;
+    struct Cin_OSS_SoundTableData state_table_data;
+};
+
+void Cin_OSS_SetSoundState(struct Cin_OSS_SoundTableData *table, int state);
+
+#define CIN_OSS_STOP(SND)\
+    Cin_OSS_SetSoundState(&((SND)->state_table_data), CIN_OSS_SOUND_STOP)
+
+#define CIN_OSS_PLAY(SND)\
+    Cin_OSS_SetSoundState(&((SND)->state_table_data), CIN_OSS_SOUND_PLAY)
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* CIN_SOUND_OSS_H */