Skip to content

Instantly share code, notes, and snippets.

@FreeApp2014
Last active September 4, 2020 19:59
Show Gist options
  • Save FreeApp2014/132addc07f2148488127f32520a56f98 to your computer and use it in GitHub Desktop.
Save FreeApp2014/132addc07f2148488127f32520a56f98 to your computer and use it in GitHub Desktop.
Library build
PLATFORMPATH="/Applications/Xcode.app/Contents/Developer/Platforms"
TOOLSPATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin"
export IPHONEOS_DEPLOYMENT_TARGET="11.0"
arch="arm64"
platform="iPhoneOS"
SDKVERSION="12.0"
clang++ -std=c++0x -O2 -arch $arch -isysroot $PLATFORMPATH/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk -miphoneos-version-min=$IPHONEOS_DEPLOYMENT_TARGET -c brstm-main.cpp -o brstm-main.o
ar r openrevolution.a brstm-main.o
//C++ BRSTM reader
//Copyright (C) 2020 Extrasklep
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include "brstm.h"
// Header definitions
Brstm* brstmp;
std::ifstream brstmfile;
unsigned char brstm_read(Brstm* brstmi,const unsigned char* fileData,signed int debugLevel,uint8_t decodeAudio);
void brstm_getbuffer(Brstm * brstmi,const unsigned char* fileData,unsigned long sampleOffset,unsigned int bufferSamples);
void brstm_fstream_getbuffer(Brstm * brstmi,std::ifstream& stream,unsigned long sampleOffset,unsigned int bufferSamples);
unsigned char brstm_fstream_read(Brstm * brstmi,std::ifstream& stream,signed int debugLevel);
void brstm_close(Brstm * brstmi);
//Getters for outer world access
extern "C" void initStruct(){
brstmp = new Brstm;
for (unsigned int c = 0; c < 16; c++){
brstmp->ADPCM_buffer[c] = nullptr;
brstmp->ADPCM_data[c] = nullptr;
brstmp->ADPCM_hsamples_1[c] = nullptr;
brstmp->ADPCM_hsamples_2[c] = nullptr;
brstmp->PCM_blockbuffer[c] = nullptr;
brstmp->PCM_buffer[c] = nullptr;
brstmp->PCM_samples[c] = nullptr;
}
}
extern "C" unsigned long gHEAD1_sample_rate(){
return brstmp->sample_rate;
};
extern "C" unsigned long gHEAD1_loop_start(){
return brstmp->loop_start;
}
extern "C" unsigned char readABrstm (const unsigned char* fileData, unsigned char debugLevel, bool decodeADPCM){
return brstm_read(brstmp, fileData, debugLevel, decodeADPCM);
}
extern "C" unsigned char readFstreamBrstm(){
return brstm_fstream_read(brstmp, brstmfile, 1);
}
extern "C" int16_t** gPCM_samples(){
return brstmp->PCM_samples;
}
extern "C" unsigned int gHEAD3_num_channels(){
return brstmp->num_channels;
}
extern "C" unsigned long gHEAD1_blocks_samples(){
return brstmp->blocks_samples;
}
extern "C" int16_t** getBufferBlock(unsigned long sampleOffset){
unsigned int readLength;
if (sampleOffset/brstmp->blocks_samples < (brstmp->total_blocks)) readLength = brstmp->blocks_samples;
else readLength = brstmp->final_block_size;
brstm_fstream_getbuffer(brstmp, brstmfile, sampleOffset, readLength);
return brstmp->PCM_buffer;
}
extern "C" int16_t** getbuffer(unsigned long offset, uint32_t frames) {
brstm_fstream_getbuffer(brstmp, brstmfile, offset, frames);
return brstmp->PCM_buffer;
}
extern "C" void closeBrstm(){
brstm_close(brstmp);
delete brstmp;
brstmfile.close();
}
extern "C" unsigned long gHEAD1_total_samples(){
return brstmp->total_samples;
}
extern "C" unsigned int gHEAD1_loop(){
return brstmp->loop_flag;
}
extern "C" int createIFSTREAMObject(char* filename){
brstmfile.open(filename);
return brstmfile.is_open();
}
extern "C" unsigned long gHEAD1_total_blocks(){
return brstmp->total_blocks;
}
extern "C" unsigned long gHEAD1_final_block_samples(){
return brstmp->final_block_samples;
}
extern "C" unsigned int gFileType(){
return brstmp->file_format;
}
extern "C" unsigned int gFileCodec() {
return brstmp->codec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment