Merge pull request #41 from badda71/master
Add SID support (libsidplay required)
This commit is contained in:
2
Makefile
2
Makefile
@@ -49,7 +49,7 @@ SOURCE_DIRS := source
|
|||||||
EXTRA_OUTPUT_FILES :=
|
EXTRA_OUTPUT_FILES :=
|
||||||
|
|
||||||
LIBRARY_DIRS := $(DEVKITPRO)/libctru $(DEVKITPRO)/portlibs/armv6k $(DEVKITPRO)/portlibs/3ds
|
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
|
BUILD_FLAGS := -Wall -Wextra -I$(DEVKITPRO)/portlibs/armv6k/include/opus -I$(DEVKITPRO)/portlibs/3ds/include/opus
|
||||||
RUN_FLAGS :=
|
RUN_FLAGS :=
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ endif
|
|||||||
IDIR =./source
|
IDIR =./source
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-I./include/
|
CFLAGS=-I./include/
|
||||||
LIBS=-lmpg123 -lvorbisidec -lopusfile -lopus -logg -lm
|
LIBS=-lsidplay -lmpg123 -lvorbisidec -lopusfile -lopus -logg -lm
|
||||||
|
|
||||||
ODIR=./build/$(HOST_ARCH)
|
ODIR=./build/$(HOST_ARCH)
|
||||||
SDIR=./source
|
SDIR=./source
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "opus.h"
|
#include "opus.h"
|
||||||
#include "vorbis.h"
|
#include "vorbis.h"
|
||||||
#include "wav.h"
|
#include "wav.h"
|
||||||
|
#include "sid.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain file type string from file_types enum.
|
* Obtain file type string from file_types enum.
|
||||||
@@ -24,7 +25,8 @@ const char* fileToStr(enum file_types ft)
|
|||||||
"FLAC",
|
"FLAC",
|
||||||
"VORBIS",
|
"VORBIS",
|
||||||
"OPUS",
|
"OPUS",
|
||||||
"MP3"
|
"MP3",
|
||||||
|
"SID"
|
||||||
};
|
};
|
||||||
|
|
||||||
return file_types_str[ft];
|
return file_types_str[ft];
|
||||||
@@ -85,6 +87,12 @@ enum file_types getFileType(const char *file)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// "PSID" or "RSID"
|
||||||
|
case 0x44495350:
|
||||||
|
case 0x44495352:
|
||||||
|
file_type=FILE_TYPE_SID;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/*
|
/*
|
||||||
* MP3 without ID3 tag, ID3v1 tag is at the end of file, or MP3
|
* MP3 without ID3 tag, ID3v1 tag is at the end of file, or MP3
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ enum file_types
|
|||||||
FILE_TYPE_FLAC,
|
FILE_TYPE_FLAC,
|
||||||
FILE_TYPE_VORBIS,
|
FILE_TYPE_VORBIS,
|
||||||
FILE_TYPE_OPUS,
|
FILE_TYPE_OPUS,
|
||||||
FILE_TYPE_MP3
|
FILE_TYPE_MP3,
|
||||||
|
FILE_TYPE_SID
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "playback.h"
|
#include "playback.h"
|
||||||
#include "vorbis.h"
|
#include "vorbis.h"
|
||||||
#include "wav.h"
|
#include "wav.h"
|
||||||
|
#include "sid.h"
|
||||||
|
|
||||||
static volatile bool stop = true;
|
static volatile bool stop = true;
|
||||||
|
|
||||||
@@ -87,6 +88,10 @@ void playFile(void* infoIn)
|
|||||||
setVorbis(&decoder);
|
setVorbis(&decoder);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FILE_TYPE_SID:
|
||||||
|
setSid(&decoder);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|||||||
123
source/sid.cpp
Normal file
123
source/sid.cpp
Normal 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
44
source/sid.h
Normal 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);
|
||||||
Reference in New Issue
Block a user