git ssb

0+

kode54 / syntrax-c



Tree: fdbf292518762b15dbc3f378ee04735cebb89f37

Files: fdbf292518762b15dbc3f378ee04735cebb89f37 / src / main_osx.cpp

3141 bytesRaw
1#include <stdio.h>
2#include <stdint.h>
3#include <signal.h>
4
5#include "audio_output.h"
6
7#include "file.h"
8
9#define SAMPLE_RATE 44100 /* 22050 - test low-pass capability of blep synthesizer */
10
11static int running;
12
13static Player * player;
14static volatile int fade_start, fade_length;
15static volatile int max_channels;
16
17void signal_handler(int sig)
18{
19 running = 0;
20 signal(sig, signal_handler);
21}
22
23void 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
42void render(void * unused, short * samples, uint32_t sampleCount)
43{
44 syntrax_info info;
45 mixChunk(player, samples, sampleCount);
46 if (playerGetSongEnded(player)) running = 0;
47 if (playerGetLoopCount(player) >= 2)
48 {
49 fade_buffer( samples, 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
56int main(int argc, const char* const* argv)
57{
58 Song * song;
59 CoreAudioStream * output;
60 syntrax_info info;
61
62 if (argc != 2)
63 {
64 fprintf(stderr, "Usage:\t%s <song>\n", argv[0]);
65 return 1;
66 }
67
68 song = File_loadSong(argv[1]);
69 if (!song)
70 {
71 fprintf(stderr, "Invalid song:\t%s\n", argv[1]);
72 return 1;
73 }
74
75 player = playerCreate(SAMPLE_RATE);
76 if (!player)
77 {
78 fprintf(stderr, "Out of memory.\n");
79 File_freeSong(song);
80 return 1;
81 }
82
83 if (loadSong(player, song) < 0)
84 {
85 fprintf(stderr, "Out of memory.\n");
86 playerDestroy(player);
87 File_freeSong(song);
88 return 1;
89 }
90
91 initSubsong(player, 0);
92
93 playerGetInfo(player, &info);
94 fprintf(stderr, "Syntrax test player v0.0001 || %i/%i\n", info.selectedSubs+1, info.totalSubs);
95 fprintf(stderr, "Title: %s\n", info.subsongName);
96 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);
97
98 signal(SIGINT, signal_handler);
99
100 output = new CoreAudioStream(render, 0, SAMPLE_RATE);
101
102 if ( output )
103 {
104 fade_start = 0; fade_length = SAMPLE_RATE * 10;
105 max_channels = 0;
106 running = 1;
107 output->start();
108 while ( running && fade_start < fade_length )
109 {
110 usleep(10000);
111 }
112 output->close();
113 fprintf(stderr, "\n");
114 }
115
116 delete output;
117
118 playerDestroy(player);
119 File_freeSong(song);
120
121 return 0;
122}
123

Built with git-ssb-web