Merge pull request #41 from badda71/master

Add SID support (libsidplay required)
This commit is contained in:
Mahyar Koshkouei
2020-05-09 10:17:01 +01:00
committed by GitHub
7 changed files with 185 additions and 4 deletions

View File

@@ -49,7 +49,7 @@ SOURCE_DIRS := source
EXTRA_OUTPUT_FILES :=
LIBRARY_DIRS := $(DEVKITPRO)/libctru $(DEVKITPRO)/portlibs/armv6k $(DEVKITPRO)/portlibs/3ds
LIBRARIES := mpg123 vorbisidec opusfile opus ogg ctru m
LIBRARIES := sidplay mpg123 vorbisidec opusfile opus ogg ctru m
BUILD_FLAGS := -Wall -Wextra -I$(DEVKITPRO)/portlibs/armv6k/include/opus -I$(DEVKITPRO)/portlibs/3ds/include/opus
RUN_FLAGS :=

View File

@@ -23,7 +23,7 @@ endif
IDIR =./source
CC=gcc
CFLAGS=-I./include/
LIBS=-lmpg123 -lvorbisidec -lopusfile -lopus -logg -lm
LIBS=-lsidplay -lmpg123 -lvorbisidec -lopusfile -lopus -logg -lm
ODIR=./build/$(HOST_ARCH)
SDIR=./source

View File

@@ -9,6 +9,7 @@
#include "opus.h"
#include "vorbis.h"
#include "wav.h"
#include "sid.h"
/**
* Obtain file type string from file_types enum.
@@ -24,7 +25,8 @@ const char* fileToStr(enum file_types ft)
"FLAC",
"VORBIS",
"OPUS",
"MP3"
"MP3",
"SID"
};
return file_types_str[ft];
@@ -84,6 +86,12 @@ enum file_types getFileType(const char *file)
errno = FILE_NOT_SUPPORTED;
break;
// "PSID" or "RSID"
case 0x44495350:
case 0x44495352:
file_type=FILE_TYPE_SID;
break;
default:
/*

View File

@@ -5,7 +5,8 @@ enum file_types
FILE_TYPE_FLAC,
FILE_TYPE_VORBIS,
FILE_TYPE_OPUS,
FILE_TYPE_MP3
FILE_TYPE_MP3,
FILE_TYPE_SID
};
/**

View File

@@ -12,6 +12,7 @@
#include "playback.h"
#include "vorbis.h"
#include "wav.h"
#include "sid.h"
static volatile bool stop = true;
@@ -86,6 +87,10 @@ void playFile(void* infoIn)
case FILE_TYPE_VORBIS:
setVorbis(&decoder);
break;
case FILE_TYPE_SID:
setSid(&decoder);
break;
default:
goto err;

123
source/sid.cpp Normal file
View File

@@ -0,0 +1,123 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sidplay/player.h>
#include "playback.h"
static uint32_t frequency = 44100;
static int channels = SIDEMU_STEREO;
static int selectedSong = 0;
static size_t buffSize = 0.5*frequency*channels; // 0.5 seconds
// don't change anything below - only 16 bit/sigend PCM is supported my ctrmus
static int sampleFormat = SIDEMU_SIGNED_PCM;
static int bitsPerSample = SIDEMU_16BIT;
emuEngine *myEmuEngine = NULL;
sidTune *myTune = NULL;
extern "C" void setSid(struct decoder_fn* decoder);
extern "C" int initSid(const char* file);
extern "C" uint32_t rateSid(void);
extern "C" uint8_t channelSid(void);
extern "C" uint64_t readSid(void* buffer);
extern "C" void exitSid(void);
/**
* Set decoder parameters for SID.
*
* \param decoder Structure to store parameters.
*/
extern "C" void setSid(struct decoder_fn* decoder)
{
decoder->init = &initSid;
decoder->rate = &rateSid;
decoder->channels = &channelSid;
decoder->buffSize = buffSize;
decoder->decode = &readSid;
decoder->exit = &exitSid;
}
/**
* Initialise SID playback.
*
* \param file Location of SID file to play.
* \return 0 on success, else failure.
*/
int initSid(const char* file)
{
// init emuEngine
myEmuEngine = new emuEngine;
if ( !myEmuEngine )
return -1;
//configure emuEngine
struct emuConfig myEmuConfig;
myEmuEngine->getConfig(myEmuConfig);
myEmuConfig.frequency = frequency;
myEmuConfig.channels = channels;
myEmuConfig.bitsPerSample = bitsPerSample;
myEmuConfig.sampleFormat = sampleFormat;
myEmuEngine->setConfig(myEmuConfig);
// load the SID file
myTune=new sidTune ( file );
if ( !myTune )
return -1;
// init emuEngine with sidTune
if ( !sidEmuInitializeSong(*myEmuEngine,*myTune,selectedSong) )
return -1;
return 0;
}
/**
* Get sampling rate of SID file.
*
* \return Sampling rate.
*/
uint32_t rateSid(void)
{
return (frequency);
}
/**
* Get number of channels of SID file.
*
* \return Number of channels for opened file.
*/
uint8_t channelSid(void)
{
return channels;
}
/**
* Read part of open SID file.
*
* \param buffer Output.
* \return Samples read for each channel.
*/
uint64_t readSid(void* buffer)
{
sidEmuFillBuffer( *myEmuEngine, *myTune, buffer, buffSize*bitsPerSample/8 );
if (myTune->getStatus())
return buffSize;
return 0;
}
/**
* Free Sid file.
*/
void exitSid(void)
{
if(myTune)
{
delete(myTune);
}
if (myEmuEngine)
{
delete(myEmuEngine);
}
}

44
source/sid.h Normal file
View File

@@ -0,0 +1,44 @@
#include <stdint.h>
#include "playback.h"
/**
* Set decoder parameters for SID.
*
* \param decoder Structure to store parameters.
*/
void setSid(struct decoder_fn* decoder);
/**
* Initialise SID playback.
*
* \param file Location of SID file to play.
* \return 0 on success, else failure.
*/
int initSid(const char* file);
/**
* Get sampling rate of SID file.
*
* \return Sampling rate.
*/
uint32_t rateSid(void);
/**
* Get number of channels of SID file.
*
* \return Number of channels for opened file.
*/
uint8_t channelSid(void);
/**
* Read part of open SID file.
*
* \param buffer Output.
* \return Samples read for each channel.
*/
uint64_t readSid(void* buffer);
/**
* Free SID file.
*/
void exitSid(void);