idk
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
namespace ReMixer {
|
||||
uint16_t createStream(const std::string& application_name, const std::string& stream_name, SampleRate sample_rate, StreamMode mode);
|
||||
SFX* loadSFX(const std::string& file);
|
||||
}
|
||||
|
||||
// this dick
|
@@ -3,6 +3,7 @@
|
||||
#include <pulse/pulseaudio.h>
|
||||
#include <pulse/simple.h>
|
||||
#include <filesystem>
|
||||
#include <ReMixer/stream.h>
|
||||
|
||||
|
||||
class PlaybackDevice {};
|
||||
@@ -10,14 +11,19 @@ class InputDevice {};
|
||||
|
||||
class Sound {
|
||||
private:
|
||||
std::vector<uint8_t> audio_data;
|
||||
std::vector<char> audio_data;
|
||||
SampleRate sample_rate;
|
||||
StreamMode num_channels;
|
||||
public:
|
||||
std::vector<uint8_t> getAudioData();
|
||||
void setAudioData(const std::vector<uint8_t>& audioData);
|
||||
uint8_t* ptr() { return audio_data.data();}
|
||||
[[nodiscard]] const uint8_t* ptr() const { return audio_data.data();}
|
||||
std::vector<char> getAudioData();
|
||||
void setAudioData(const std::vector<char>& audioData);
|
||||
void setNumberOfChannels(StreamMode mode);
|
||||
void setSampleRate(SampleRate rate);
|
||||
SampleRate getSampleRate();
|
||||
[[nodiscard]] unsigned int getNumberOfChannels() const;
|
||||
char* ptr() { return audio_data.data();}
|
||||
[[nodiscard]] const char* ptr() const { return audio_data.data();}
|
||||
Sound() = default;
|
||||
explicit Sound(const std::vector<uint8_t>& audioData);
|
||||
};
|
||||
|
||||
|
||||
@@ -26,10 +32,7 @@ public:
|
||||
class SFX : public Sound {
|
||||
public:
|
||||
SFX() = default;
|
||||
SFX(const std::filesystem::path& sfx_file_path)
|
||||
{
|
||||
|
||||
}
|
||||
SFX(const std::string& sfx_file_path)
|
||||
};
|
||||
|
||||
/// Longer (>10 second) audio via WAV format.
|
||||
|
39
main.cpp
39
main.cpp
@@ -11,48 +11,9 @@
|
||||
#include <iostream>
|
||||
#include <ReMixer/stream.h>
|
||||
#include <ReMixer/sound.h>
|
||||
|
||||
#include <vorbis/codec.h>
|
||||
#include <vorbis/vorbisfile.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
void decodeVorbis(const char* inputFile, const char* outputFile)
|
||||
{
|
||||
OggVorbis_File vf;
|
||||
FILE* inFile = fopen(inputFile, "rb");
|
||||
if (!inFile) {
|
||||
std::cerr << "Error opening input file." << std::endl; return;
|
||||
}
|
||||
|
||||
if (ov_open(inFile, &vf, NULL, 0) < 0) {
|
||||
std::cerr << "Error opening Ogg Vorbis file." << std::endl;
|
||||
fclose(inFile);
|
||||
return;
|
||||
}
|
||||
vorbis_info* vi = ov_info(&vf, -1);
|
||||
|
||||
std::ofstream outFile(outputFile, std::ios::binary);
|
||||
if (!outFile.is_open()) {
|
||||
std::cerr << "Error opening output file." << std::endl;
|
||||
ov_clear(&vf);
|
||||
fclose(inFile);
|
||||
return;
|
||||
}
|
||||
|
||||
char pcmout[4096];
|
||||
int current_section;
|
||||
long bytes;
|
||||
|
||||
while ((bytes = ov_read(&vf, pcmout, sizeof(pcmout), 0, 2, 1, ¤t_section)) > 0) {
|
||||
outFile.write(pcmout, bytes);
|
||||
}
|
||||
|
||||
outFile.close();
|
||||
ov_clear(&vf);
|
||||
fclose(inFile);
|
||||
}
|
||||
|
||||
[[noreturn]] int main() {
|
||||
const char* inputFile = "input.ogg";
|
||||
const char* outputFile = "output.raw";
|
||||
|
@@ -4,4 +4,8 @@ uint16_t ReMixer::createStream(const std::string& application_name, const std::s
|
||||
auto s = Stream(application_name, stream_name, sample_rate, mode);
|
||||
return s.handle;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
SFX* ReMixer::loadSFX(const std::string& file) {
|
||||
return new SFX(file);
|
||||
}
|
||||
|
@@ -1,12 +1,63 @@
|
||||
#include <ReMixer/sound.h>
|
||||
std::vector<uint8_t> Sound::getAudioData() {
|
||||
#include <vorbis/codec.h>
|
||||
#include <vorbis/vorbisfile.h>
|
||||
|
||||
std::vector<char> Sound::getAudioData() {
|
||||
return audio_data;
|
||||
}
|
||||
|
||||
void Sound::setAudioData(const std::vector<uint8_t>& audioData) {
|
||||
void Sound::setAudioData(const std::vector<char>& audioData) {
|
||||
audio_data = audioData;
|
||||
}
|
||||
|
||||
Sound::Sound(const std::vector<uint8_t>& audioData) {
|
||||
setAudioData(audioData);
|
||||
unsigned int Sound::getNumberOfChannels() const {
|
||||
return (unsigned int) num_channels + 1;
|
||||
}
|
||||
|
||||
SampleRate Sound::getSampleRate() {
|
||||
return sample_rate;
|
||||
}
|
||||
|
||||
void Sound::setNumberOfChannels(StreamMode mode) {
|
||||
num_channels = mode;
|
||||
|
||||
}
|
||||
|
||||
void Sound::setSampleRate(SampleRate rate) {
|
||||
sample_rate = rate;
|
||||
}
|
||||
|
||||
SFX::SFX(const std::string& sfx_file_path) {
|
||||
OggVorbis_File vf;
|
||||
FILE* inFile = fopen(sfx_file_path.c_str(), "rb");
|
||||
|
||||
if (!inFile)
|
||||
throw std::runtime_error(std::string("Couldn't open the input file " + sfx_file_path));
|
||||
|
||||
if (ov_open(inFile, &vf, nullptr, 0) < 0)
|
||||
throw std::runtime_error(std::string("libVorbis couldn't open the input file " + sfx_file_path));
|
||||
|
||||
vorbis_info* vi = ov_info(&vf, -1);
|
||||
|
||||
char pcmout[4096];
|
||||
std::vector<char> raw_audio;
|
||||
int current_section;
|
||||
long bytes;
|
||||
|
||||
while ((bytes = ov_read(&vf, pcmout, sizeof(pcmout), 0, 2, 1, ¤t_section)) > 0)
|
||||
raw_audio.insert(raw_audio.end(), pcmout, pcmout + bytes);
|
||||
|
||||
|
||||
if (vi->channels == 1)
|
||||
setNumberOfChannels(StreamMode::MONO);
|
||||
else if (vi->channels == 2)
|
||||
setNumberOfChannels(StreamMode::STEREO);
|
||||
|
||||
if (vi->rate == 44100)
|
||||
setSampleRate(SampleRate::STANDARD);
|
||||
else if (vi->rate == 48000)
|
||||
setSampleRate(SampleRate::HIGH);
|
||||
|
||||
ov_clear(&vf);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user