Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411279 Posts in 69323 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 03:19:54 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Using the PxTone library in C++
Pages: [1]
Print
Author Topic: Using the PxTone library in C++  (Read 5120 times)
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« on: May 10, 2008, 05:22:43 PM »

Hey all, I've got a technical question:

I'm working on a little side project at the moment, and I thought it might be cool to use PxTone for the music. Unfortunately, I can't seem to get it to play anything, and I don't know why.

Someone over at the doukutsu livejournal community apparently had the same problem, but his solution doesn't work for me.

Here's where I am: I'm using the pxtone dll, the pxtone.lib file, both of which come in the pxtone package on Pixel's site. I'm also using this version of pxtone.h which is translated into english, which I found through google:

Code: (pxtone.h)
#ifdef PXTONEDLL_EXPORTS
#define DLLAPI __declspec(dllexport) // Declare for DLL export
#else
#define DLLAPI __declspec(dllimport) // Declare for DLL import
#endif

// We want C instead of C++.
#ifdef __cplusplus
extern "C"{
#endif

typedef BOOL (* PXTONEPLAY_CALLBACK)( long clock );

// pxtone functions follow ===================================


// Initialise pxtone.
BOOL DLLAPI pxtone_Ready(
    HWND hWnd,          // Please supply window handle
    long channel_num,   // Please specify the number of channels (1:Mono / 2:Stereo)
    long sps,           // Per-second sampling rate (11025 / 22050 / 44100)
    long bps,           // Beat count per 1 sample ( 8 / 16 )
    float buffer_sec,   // Song buffer size, used to play a song (0.1 recommended)
    BOOL bDirectSound,  // TRUE: Use DirectSound / FALSE: Use WAVEMAPPER.
    PXTONEPLAY_CALLBACK pProc // Function called for each sample.  Can be NULL.
); // pxtone declaration

// Reconfigure pxtone.
BOOL DLLAPI pxtone_Reset(
    HWND hWnd,
    long channel_num,
    long sps,
    long bps,
    float buffer_sec,
    BOOL bDirectSound,
    PXTONEPLAY_CALLBACK pProc
);

// pxtone generates a DirectSound pointer (LPDIRECTSOUND).
// Please be careful not to release DirectSound itself.
void DLLAPI *pxtone_GetDirectSound( void );

// Aquires the previous error string
const char DLLAPI* pxtone_GetLastError( void );

// Get the pxtone quality
void DLLAPI pxtone_GetQuality( long *p_channel_num, long *p_sps, long *p_bps, long *p_sample_per_buf ); // pxtone

// Release pxtone.
BOOL DLLAPI pxtone_Release( void );

// Load a song (from a resource file)
BOOL DLLAPI pxtone_Tune_Load(
    HMODULE hModule,       // If you are reading a resource from a module handle.
                           // It's no problem for this to be NULL.
    const char *type_name, // The resource type if you are reading from a resource.
                           // For reading external files, this is NULL.
    const char *file_name  // Resource file name or path and filename.
    );

// Load a song (from memory)
BOOL DLLAPI pxtone_Tune_Read( void* p, long size );

// Free a song
BOOL DLLAPI pxtone_Tune_Release( void );

// Play the song
BOOL DLLAPI pxtone_Tune_Start(
    long start_sample,     // Start position.  Stop and Fadeout mainly use these values.  0 is the first.
    long fadein_msec       // Fade-in time from this position (milliseconds).
    );

// Fade out playback starting on next sample.
long DLLAPI pxtone_Tune_Fadeout( long msec );

// Set the song volume.  Up to 1.0, 0.5 is half.
void DLLAPI pxtone_Tune_SetVolume( float v );

// Stop sampling for currently playing song
long DLLAPI pxtone_Tune_Stop( void );

// Determines whether playing.
BOOL DLLAPI pxtone_Tune_IsStreaming( void );

// Set playback looping ON / OFF.
void DLLAPI pxtone_Tune_SetLoop( BOOL bLoop );

// Get information about the song.
void DLLAPI pxtone_Tune_GetInformation( long *p_beat_num, float *p_beat_tempo, long *p_beat_clock, long *p_meas_num );

// Get start-of-repeat measure.
long DLLAPI pxtone_Tune_GetRepeatMeas( void );

// Get the effective performance measure (LAST event measure, if you do not have a final measure)
long DLLAPI pxtone_Tune_GetPlayMeas(   void );

// Get the name of the song.
const char DLLAPI* pxtone_Tune_GetName(    void );

// Get the song comments.
const char DLLAPI* pxtone_Tune_GetComment( void );


// Specifies address to which to write playback buffer
BOOL DLLAPI pxtone_Tune_Vomit(
    void* p,         // The address of the playback buffer
    long sample_num  // Number of samples to write
    );

// Returns:  TRUE if you have not yet continued, FALSE otherwise
// 1. If you use this function, please set buffer_sec of pxtone_Ready() to 0.
//    pxtone streaming feature is disabled.
// 2. After a call to this function, call pxtone_Tune_Start() to load song.
// 3. sample_num sample size is not the sample number.
//    Ex)  11025hz 2ch 8bit will spit out a double value, even though sample_num
//         specifies 11025.  22050 bytes are written to the playback buffer.
// 4. Streaming functions are similarly valid, e.g. pxtone_Tune_Fadeout().


#ifdef __cplusplus
}
#endif

I'm using Allegro, so in my program I #include <winalleg.h> (so that I can access the windows stuff) and #include "pxtone.h", I link in pxtone.lib, and in the main code I do the following, which should load and play the song: (win_get_window() is an allegro function to return the window handler)

Code:
char* song = "mysong.pttune";
pxtone_Ready(win_get_window(), 2, 44100, 16, 0.1, TRUE, NULL);
pxtone_Tune_Load(NULL, NULL, song);
pxtone_Tune_SetVolume(1.0f);
pxtone_Tune_Start(0,0);

I don't get any errors, but I don't hear anything either. Any advice? Sad It's probably something silly!
« Last Edit: May 10, 2008, 05:26:14 PM by Terry » Logged

Annabelle Kennedy
Awesomesauce
Level 8
*


♥Android Love♥


View Profile
« Reply #1 on: May 10, 2008, 09:48:00 PM »

thats really really bizarre.

just for fun, i took your exact code to use the PXtone

put it into my TSH editor i was working on..
linked and added the includes.. and it just worked.

haha... im using the original header though, and not the tranlsated one, the function calls are still the same.  im not sure if that has anything to do with it.
Logged
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #2 on: May 11, 2008, 04:39:59 AM »

Ok, I guess it was something silly! Shocked I'd misspelt the filename! At least it's working now!



Nothing to see here :D Thanks for the reply, Annabelle!
Logged

increpare
Guest
« Reply #3 on: June 15, 2008, 06:21:01 AM »

Terry, I remember you saying that you decided against using this library in the end because it was so goddamned slow; I wonder if there would be a way of getting it to render whole pxtone files when the game started up, and just playing them straight; possibly using the vomit command (to my knowledge pxtone renders its files on the fly).  Anyone here know about this?
Logged
Terry
TIGSource Editor
Level 10
******



View Profile WWW
« Reply #4 on: June 15, 2008, 11:33:05 AM »

sorry, don't know what the vomit command is. There probably were some solutions to the speed problem of pxtone though - I didn't really give it a proper chance, so I wouldn't be put off by my experience with it.

At the very least, if you really wanted to use Pxtone to compose your music you could convert them to wavs then oggs and use them that way - I've never had any speed problems with the ogg libraries I've used.
Logged

increpare
Guest
« Reply #5 on: June 15, 2008, 02:16:05 PM »

Oh gosh, I just looked up ogg libraries on google, and came across Bass again.  Man: serious nostalgia; I remember using that years and years ago, though I can't remember what for anymore. Main problem with OGGs is that they're probably going to be pretty big.  Anyway, I'll play about with various audio libraries soon enough.
Logged
raigan
Level 5
*****


View Profile
« Reply #6 on: June 16, 2008, 03:01:54 PM »

man, it would be awesome if someone would write a simple realtime-synth-based sound library. anyone? Smiley
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #7 on: June 16, 2008, 03:59:50 PM »

http://www.ludumdare.com/compo/2007/12/13/sfxr-sound-effects-for-all/

I implemented SFXR's sound rendering into my engine pretty painlessly and it works great.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
raigan
Level 5
*****


View Profile
« Reply #8 on: June 17, 2008, 07:07:27 AM »

awesome! i thought it was just a stand-along wav-rendering tool..
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #9 on: June 17, 2008, 07:11:47 AM »

It is, but it saves its own sound format that describes the wave, and has very well written and easy to use code, which you can use to render them. I should talk to Dr. Petter about making it into a proper library.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic