1 //just gonna see if i can display a hively position list and all the hively tracks and make it scroll
8 #include "hvl_replay.h"
10 #include "pineapple.h"
14 #define HIVELY_LEN FREQ/50
15 #define OUTPUT_LEN 4096
17 int16 hivelyLeft
[HIVELY_LEN
], hivelyRight
[HIVELY_LEN
];
20 void mix_and_play( struct hvl_tune
*ht
, uint8
*stream
, int length
);
27 if(SDL_Init(SDL_INIT_AUDIO
)< 0) {
28 printf("Could not initialize SDL: %s\n", SDL_GetError());
34 wanted
.format
= AUDIO_S16SYS
;
35 wanted
.channels
= 2; /* 1 = mono, 2 = stereo */
36 wanted
.samples
= OUTPUT_LEN
; // HIVELY_LEN;
38 wanted
.callback
= (void*) mix_and_play
;
39 wanted
.userdata
= tune
;
41 if(SDL_OpenAudio(&wanted
, NULL
) < 0) {
42 printf("Failed to open audio device.\n");
50 void mix_and_play( struct hvl_tune
*ht
, uint8
*stream
, int length
)
58 samples
= tune
->ht_Frequency
/50/ht
->ht_SpeedMultiplier
;
61 // Mix to 16bit interleaved stereo
62 out
= (int16
*) stream
;
63 // Flush remains of previous frame
64 for(i
= hivelyIndex
; i
< (HIVELY_LEN
); i
++) {
65 out
[streamPos
++] = hivelyLeft
[i
];
66 out
[streamPos
++] = hivelyRight
[i
];
69 while(streamPos
< length
) {
70 hvl_DecodeFrame( tune
, (int8
*) hivelyLeft
, (int8
*) hivelyRight
, 2 );
71 for(i
= 0; i
< (HIVELY_LEN
) && streamPos
< length
; i
++) {
72 out
[streamPos
++] = hivelyLeft
[i
];
73 out
[streamPos
++] = hivelyRight
[i
];
77 } else if(tune
&& plonked
) {
78 // Mix to 16bit interleaved stereo
79 out
= (int16
*) stream
;
80 // Flush remains of previous frame
81 for(i
= hivelyIndex
; i
< (HIVELY_LEN
); i
++) {
82 out
[streamPos
++] = hivelyLeft
[i
];
83 out
[streamPos
++] = hivelyRight
[i
];
86 while(streamPos
< length
) {
87 hvl_playNote( tune
, (int8
*) hivelyLeft
, (int8
*) hivelyRight
, 2, &tune
->ht_Voices
[0]);
88 for(i
= 0; i
< (HIVELY_LEN
) && streamPos
< length
; i
++) {
89 out
[streamPos
++] = hivelyLeft
[i
];
90 out
[streamPos
++] = hivelyRight
[i
];
97 int main(int argc
, char *argv
[])
99 hivelyIndex
= HIVELY_LEN
;
101 printf( "Usage: play_hvl <tune>\n" );
107 tune
= hvl_LoadTune(argv
[1], FREQ
, 4);
112 hvl_InitSubsong( tune
, 0 );