• Welcome to Dark Bit Factory & Gravity.
 

Tiny SID Player for Freebasic and C

Started by Jim, August 29, 2007

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stormbringer

Here it is:

  TinySID v1.0 Generic Replay

  based on PSP original source code by Tammo Hinrichs & Rainer Sinsch

  changes made:

  - removed any platform/audio device/audio mechanism dependency
  - original comments kept
  - code cleaned
  - added new comments to make code clearer to read
  - functions renamed to avoid conflict with other functions in client programs (all have sid_ prefix now)
  - removed local variables
  - added SIDEmulator structure that holds the state of the emulator (memory, registers, etc)
  - changed the compilation-time audio filtering with a run-time audio filtering flag

  instructions:

  1) declare a variable of the type SIDEmulator (emulator state)
  2) call sid_emu_init() with the address of the emulator state variable and replay frequency (e.g. 44100)
  3) call sid_emu_load_from_mem() with the address of the emulator variable and the address and size of the SID tune
   to be loaded in the emulator memory
  4) call sid_emu_process_begin() with the address of the emulator variable and the number of the sub-song (zero-based number) to be replayed
   you may want to call sid_emu_get_subsong_count() before to know how may sub-songs are contained in the file
  5) call sid_emu_process() during your audio interrupt/callback to render new samples.

  NOTE: the audio stream is rendered as MONO not STEREO!
  NOTE2: you may call sid_emu_audio_filter() to turn on and off the audio filtering (works at run-time)


Archive includes Win32 WaveOut sound server example in C.

Have fun!
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Rbz

Welldone, I guess I'll make a FB port ;)
Challenge Trophies Won:

Clyde

That would be very cool indeed.  8)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

stormbringer

@Rbraz: definitely needed I guess. By reading this thread, I think a lot of people are waiting for a lib that fixes the bugs of the past one... it should be easier now with the source code..
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Clyde

Can it play RSID tunes as well as PSID?

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

stormbringer

AFAIK it only plays PSIDs... I did not look into RSIDs yet. I just cleaned the original code (which is not by me) and made it available here so we can have this lib whithout the need to link DirectX and other crap in order to replay some good old tunes ;)
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

stormbringer

We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Rbz

Ok, it's done  :)

I did a little change on original "sid_sound_server_replay_init" function, I use it to pass song parameters to the emulator.
Check out example test included.

:cheers:
Challenge Trophies Won:

benny!

@stormbringer+rbz:
K++ to you both (when I can give K again). Great work.

@stormbringer:
thanks a lot for that cool Rob videos. Brings a lot of
memories back - very retro  O0
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Shockwave

You know what, having the directx one that Jim ported was really nice, I was dissapointed when it wouldnt work reliably everywhere though. This is not Jim's fault, Direct X is lame and cannot be guaranteed to work anywhere and should be banished to the bottom of the deepest ocean where there is no light and it can be eaten by deformed sea creatures.

Now there is a viable and working version that uses Hwave!

So I will respectfully tip my hat to these people;

Jim (for getting the ball rolling).
Stormbringer for the hard work in porting this and giving it to the community.
Rbz for the lightning quick port over to Freebasic.

Yes, we have the best selection of working sound libraries anywhere on the scene in this forum and for helping that remain the case, K + 10 to all three of you.

Thank you very very very much.
Shockwave ^ Codigos
Challenge Trophies Won:

stormbringer

@benny! & Shockwave: thanks you guys! It was not really "hard work" as the original code did not have issues with compilation or anything. It was just done by somebody who seems to be a student in computer science and done for what seemed to be a school's end-of-the-year project. I mean by that that the code was not very structured and organized. I just "cleaned the house" a bit.

Note to developers: if you want to reuse the replay routine only (C/C++) version, just steal the sid_emu.c and sid_emu.h files from the archive. The WaveOut sound server was provided as an example. The core routines just render the samples into a provided buffer. Then you can redirect the buffer to whatever you want: WaveOut, DirectSound, etc.

Since now the emulator's state is contained in a structure, it is multi-thread safe and you can have several SID emulators running in parallel. That can be usefull for cross-fading between songs, etc.

It is also a good practice to keep the replay routine separated from the audio output mechanism. The example I provided could work well for a simple production (intro/demo) but I would not use it "as is" for something more complex, like a player (e.g. WinAmp, etc).
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

energy

Wow Stormbringer!!  :goodpost:
Thanx and k++ for this cool Prod....

Runs FINE with RRAZ LIB Version under PUREBASIC....
I'll deliver tomorrow the Purebasic version with source...

@Stormbringer and RBRAZ:   :-*

Cheers
eNeRGy
coding: jwasm,masm
hobby: www.scd2003.de

stormbringer

@energy: thanks mate!

@energy+rbraz: may I ask you to upload your libs here : http://retro-remakes.net/index.php?board=64.0

Thanks in advance!
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

energy

coding: jwasm,masm
hobby: www.scd2003.de

stormbringer

We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

energy

Hi!
Here's conversion for Purebasic.
Big thanx go to Stormbringer and Rbraz for this great Lib...   :-*

Cheers eNeRGy


http://retro-remakes.net/index.php?topic=226.0
coding: jwasm,masm
hobby: www.scd2003.de

mudlord

Awesome! I just noticed this and its pretty nice for its size!

All we need now is a decent AHX/HVL library in the same fashion!

*hint hint*....

stormbringer

will come.... just a bit of patience ;)
We once had a passion
It all seemed so right
So young and so eager
No end in sight
But now we are prisoners
In our own hearts
Nothing seems real
It's all torn apart

Jim

#78
There is an AHX library around here somewhere too.  I used it in my Scroller demo... If anyone wants that source please just ask.  It's had a number of fixes and now doesn't rely on a C runtime, plus, for those luddites, it can be configured to use WaveOut instead of DirectSound.

<edit>
http://dbfinteractive.com/forum/index.php?topic=990.0
It was one of m0d's tunes I used.  Great tune, I just wish he'd hung around long enough for the K!

Jim
Challenge Trophies Won:

turkeybaster5723

I'm considering porting this to AS3/Flash. Cause that's my thing, really. And, errrrr, masochism, yes.
I do remember TinySID being an unreliable mess and am currently looking at this 1.0 version.

Welp, here's my introductory post, and with it, my first necrobump.

Cheers *hides*