Commit ccbcc93b4e2df83c81f0bf9633f3ab416908e84b
Fix subsong name info.
Christopher Snowhill authored on 1/12/2016, 8:04:09 AMChristopher Snowhill committed on 6/13/2018, 12:10:58 AM
Parent: bff8b8a36f298d4d4b58de609058a7608cacf8a2
Files changed
src/syntrax/syntrax.c | changed |
src/syntrax/syntrax.h | changed |
src/main_osx.c | deleted |
src/main_osx.cpp | added |
src/syntrax/syntrax.c | ||
---|---|---|
@@ -2334,9 +2334,9 @@ | ||
2334 | 2334 | { |
2335 | 2335 | int i, j; |
2336 | 2336 | info->coarse = p->posCoarse; |
2337 | 2337 | info->fine = p->posFine; |
2338 | - info->subsongName = &p->curSubsong.m_Name; | |
2338 | + info->subsongName = p->curSubsong.m_Name; | |
2339 | 2339 | info->selectedSubs = p->selectedSubsong; |
2340 | 2340 | info->totalSubs = p->synSong->h.subsongNum; |
2341 | 2341 | for (i = 0, j = 0; i < p->channelNumber; i++) |
2342 | 2342 | { |
src/syntrax/syntrax.h | ||
---|---|---|
@@ -351,9 +351,9 @@ | ||
351 | 351 | { |
352 | 352 | unsigned char coarse; |
353 | 353 | unsigned char fine; |
354 | 354 | unsigned char channelsPlaying; |
355 | - char *subsongName; | |
355 | + const char *subsongName; | |
356 | 356 | int selectedSubs; |
357 | 357 | int totalSubs; |
358 | 358 | } syntrax_info; |
359 | 359 |
src/main_osx.c | ||
---|---|---|
@@ -1,113 +1,0 @@ | ||
1 | - | |
2 | - | |
3 | - | |
4 | - | |
5 | - | |
6 | - | |
7 | - | |
8 | - | |
9 | - | |
10 | -static int running; | |
11 | - | |
12 | -void signal_handler(int sig) | |
13 | -{ | |
14 | - running = 0; | |
15 | - signal(sig, signal_handler); | |
16 | -} | |
17 | - | |
18 | -void fade_buffer(signed short *buffer, unsigned int count, int fade_start, int fade_length) | |
19 | -{ | |
20 | - unsigned int i; | |
21 | - for (i = 0; i < count; i++) | |
22 | - { | |
23 | - if (fade_start < fade_length) | |
24 | - { | |
25 | - buffer[ i * 2 + 0 ] = (int64_t)((int64_t)buffer[ i * 2 + 0 ] * ( fade_length - fade_start )) / fade_length; | |
26 | - buffer[ i * 2 + 1 ] = (int64_t)((int64_t)buffer[ i * 2 + 1 ] * ( fade_length - fade_start )) / fade_length; | |
27 | - fade_start++; | |
28 | - } | |
29 | - else | |
30 | - { | |
31 | - buffer[ i * 2 + 0 ] = 0; | |
32 | - buffer[ i * 2 + 1 ] = 0; | |
33 | - } | |
34 | - } | |
35 | -} | |
36 | - | |
37 | -int main(int argc, const char* const* argv) | |
38 | -{ | |
39 | - Song * song; | |
40 | - Player * player; | |
41 | - ao_device * dev; | |
42 | - ao_sample_format fmt = { 16, SAMPLE_RATE, 2, AO_FMT_NATIVE, 0 }; | |
43 | - | |
44 | - signed short sample_buffer[2048 * 2]; | |
45 | - | |
46 | - if (argc != 2) | |
47 | - { | |
48 | - fprintf(stderr, "Usage:\t%s <song>\n", argv[0]); | |
49 | - return 1; | |
50 | - } | |
51 | - | |
52 | - song = File_loadSong(argv[1]); | |
53 | - if (!song) | |
54 | - { | |
55 | - fprintf(stderr, "Invalid song:\t%s\n", argv[1]); | |
56 | - return 1; | |
57 | - } | |
58 | - | |
59 | - player = playerCreate(SAMPLE_RATE); | |
60 | - if (!player) | |
61 | - { | |
62 | - fprintf(stderr, "Out of memory.\n"); | |
63 | - File_freeSong(song); | |
64 | - return 1; | |
65 | - } | |
66 | - | |
67 | - if (loadSong(player, song) < 0) | |
68 | - { | |
69 | - fprintf(stderr, "Out of memory.\n"); | |
70 | - playerDestroy(player); | |
71 | - File_freeSong(song); | |
72 | - return 1; | |
73 | - } | |
74 | - | |
75 | - initSubsong(player, 0); | |
76 | - | |
77 | - signal(SIGINT, signal_handler); | |
78 | - | |
79 | - ao_initialize(); | |
80 | - | |
81 | - dev = ao_open_live( ao_default_driver_id(), &fmt, NULL ); | |
82 | - | |
83 | - if ( dev ) | |
84 | - { | |
85 | - int fade_start = 0, fade_length = SAMPLE_RATE * 10; | |
86 | - int max_channels = 0; | |
87 | - syntrax_info info; | |
88 | - running = 1; | |
89 | - while ( running && fade_start < fade_length ) | |
90 | - { | |
91 | - mixChunk(player, sample_buffer, 2048); | |
92 | - if (playerGetSongEnded(player)) break; | |
93 | - if (playerGetLoopCount(player) >= 2) | |
94 | - { | |
95 | - fade_buffer( sample_buffer, 2048, fade_start, fade_length ); | |
96 | - fade_start += 2048; | |
97 | - } | |
98 | - ao_play( dev, (char*) sample_buffer, 2048 * 4 ); | |
99 | - playerGetInfo(player, &info); | |
100 | - fprintf(stderr, "\ro: %3u - r: %2u - c: %2u (%2u)", info.coarse, info.fine, info.channelsPlaying, info.channelsPlaying > max_channels ? max_channels = info.channelsPlaying : max_channels); | |
101 | - } | |
102 | - fprintf(stderr, "\n"); | |
103 | - | |
104 | - ao_close( dev ); | |
105 | - } | |
106 | - | |
107 | - ao_shutdown(); | |
108 | - | |
109 | - playerDestroy(player); | |
110 | - File_freeSong(song); | |
111 | - | |
112 | - return 0; | |
113 | -} |
src/main_osx.cpp | ||
---|---|---|
@@ -1,0 +1,116 @@ | ||
1 | + | |
2 | + | |
3 | + | |
4 | + | |
5 | + | |
6 | + | |
7 | + | |
8 | + | |
9 | + | |
10 | + | |
11 | +static int running; | |
12 | + | |
13 | +static Player * player; | |
14 | +static volatile int fade_start, fade_length; | |
15 | +static volatile int max_channels; | |
16 | + | |
17 | +void signal_handler(int sig) | |
18 | +{ | |
19 | + running = 0; | |
20 | + signal(sig, signal_handler); | |
21 | +} | |
22 | + | |
23 | +void fade_buffer(signed short *buffer, unsigned int count, int fade_start, int fade_length) | |
24 | +{ | |
25 | + unsigned int i; | |
26 | + for (i = 0; i < count; i++) | |
27 | + { | |
28 | + if (fade_start < fade_length) | |
29 | + { | |
30 | + buffer[ i * 2 + 0 ] = (int64_t)((int64_t)buffer[ i * 2 + 0 ] * ( fade_length - fade_start )) / fade_length; | |
31 | + buffer[ i * 2 + 1 ] = (int64_t)((int64_t)buffer[ i * 2 + 1 ] * ( fade_length - fade_start )) / fade_length; | |
32 | + fade_start++; | |
33 | + } | |
34 | + else | |
35 | + { | |
36 | + buffer[ i * 2 + 0 ] = 0; | |
37 | + buffer[ i * 2 + 1 ] = 0; | |
38 | + } | |
39 | + } | |
40 | +} | |
41 | + | |
42 | +void render(void * unused, short * samples, uint32_t sampleCount) | |
43 | +{ | |
44 | + syntrax_info info; | |
45 | + mixChunk(player, sample_buffer, sampleCount); | |
46 | + if (playerGetSongEnded(player)) running = 0; | |
47 | + if (playerGetLoopCount(player) >= 2) | |
48 | + { | |
49 | + fade_buffer( sample_buffer, sampleCount, fade_start, fade_length ); | |
50 | + fade_start += sampleCount; | |
51 | + } | |
52 | + playerGetInfo(player, &info); | |
53 | + fprintf(stderr, "\ro: %3u - r: %2u - c: %2u (%2u)", info.coarse, info.fine, info.channelsPlaying, info.channelsPlaying > max_channels ? max_channels = info.channelsPlaying : max_channels); | |
54 | +} | |
55 | + | |
56 | +int main(int argc, const char* const* argv) | |
57 | +{ | |
58 | + Song * song; | |
59 | + CoreAudioStream * output; | |
60 | + | |
61 | + if (argc != 2) | |
62 | + { | |
63 | + fprintf(stderr, "Usage:\t%s <song>\n", argv[0]); | |
64 | + return 1; | |
65 | + } | |
66 | + | |
67 | + song = File_loadSong(argv[1]); | |
68 | + if (!song) | |
69 | + { | |
70 | + fprintf(stderr, "Invalid song:\t%s\n", argv[1]); | |
71 | + return 1; | |
72 | + } | |
73 | + | |
74 | + player = playerCreate(SAMPLE_RATE); | |
75 | + if (!player) | |
76 | + { | |
77 | + fprintf(stderr, "Out of memory.\n"); | |
78 | + File_freeSong(song); | |
79 | + return 1; | |
80 | + } | |
81 | + | |
82 | + if (loadSong(player, song) < 0) | |
83 | + { | |
84 | + fprintf(stderr, "Out of memory.\n"); | |
85 | + playerDestroy(player); | |
86 | + File_freeSong(song); | |
87 | + return 1; | |
88 | + } | |
89 | + | |
90 | + initSubsong(player, 0); | |
91 | + | |
92 | + signal(SIGINT, signal_handler); | |
93 | + | |
94 | + output = new CoreAudioPlayer(render, SAMPLE_RATE); | |
95 | + | |
96 | + if ( output ) | |
97 | + { | |
98 | + fade_start = 0; fade_length = SAMPLE_RATE * 10; | |
99 | + max_channels = 0; | |
100 | + running = 1; | |
101 | + output->start(); | |
102 | + while ( running && fade_start < fade_length ) | |
103 | + { | |
104 | + usleep(10000); | |
105 | + } | |
106 | + output->close(); | |
107 | + fprintf(stderr, "\n"); | |
108 | + } | |
109 | + | |
110 | + delete output; | |
111 | + | |
112 | + playerDestroy(player); | |
113 | + File_freeSong(song); | |
114 | + | |
115 | + return 0; | |
116 | +} |
Built with git-ssb-web