xref: /btstack/example/mod_player.c (revision 036e10079a77215137b087eeca70f0a6f3513b84)
1f8903005SMatthias Ringwald /*
2f8903005SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3f8903005SMatthias Ringwald  *
4f8903005SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5f8903005SMatthias Ringwald  * modification, are permitted provided that the following conditions
6f8903005SMatthias Ringwald  * are met:
7f8903005SMatthias Ringwald  *
8f8903005SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9f8903005SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10f8903005SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11f8903005SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12f8903005SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13f8903005SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14f8903005SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15f8903005SMatthias Ringwald  *    from this software without specific prior written permission.
16f8903005SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17f8903005SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18f8903005SMatthias Ringwald  *    monetary gain.
19f8903005SMatthias Ringwald  *
20f8903005SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21f8903005SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22f8903005SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25f8903005SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26f8903005SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27f8903005SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28f8903005SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29f8903005SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30f8903005SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31f8903005SMatthias Ringwald  * SUCH DAMAGE.
32f8903005SMatthias Ringwald  *
33f8903005SMatthias Ringwald  * Please inquire about commercial licensing options at
34f8903005SMatthias Ringwald  * [email protected]
35f8903005SMatthias Ringwald  *
36f8903005SMatthias Ringwald  */
37f8903005SMatthias Ringwald 
38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "mod_player.c"
39ec8ae085SMilanka Ringwald // *****************************************************************************
40ec8ae085SMilanka Ringwald /* EXAMPLE_START(mod_player): Audio Driver - Play 80's MOD Song
41ec8ae085SMilanka Ringwald  *
42ec8ae085SMilanka Ringwald  */
43bb2a7656SMatthias Ringwald 
44f8903005SMatthias Ringwald #include "btstack.h"
45f8903005SMatthias Ringwald #include "hxcmod.h"
46f8903005SMatthias Ringwald #include "mods/mod.h"
47b0e4fcd5SMatthias Ringwald #include <stdio.h>
48f8903005SMatthias Ringwald 
49f8903005SMatthias Ringwald static modcontext mod_context;
50f8903005SMatthias Ringwald 
audio_playback(int16_t * buffer,uint16_t num_samples)51f8903005SMatthias Ringwald static void audio_playback(int16_t * buffer, uint16_t num_samples){
52*036e1007SMatthias Ringwald 	hxcmod_fillbuffer(&mod_context, buffer, num_samples, NULL);
53f8903005SMatthias Ringwald }
54f8903005SMatthias Ringwald 
55f8903005SMatthias Ringwald int btstack_main(int argc, const char * argv[]);
btstack_main(int argc,const char * argv[])56f8903005SMatthias Ringwald int btstack_main(int argc, const char * argv[]){
57f8903005SMatthias Ringwald     (void)argc;
58f8903005SMatthias Ringwald     (void)argv;
59f8903005SMatthias Ringwald 
60f8903005SMatthias Ringwald     // load mod
61f8903005SMatthias Ringwald 	int hxcmod_initialized = hxcmod_init(&mod_context);
62f8903005SMatthias Ringwald     if (!hxcmod_initialized) return 10;
63f8903005SMatthias Ringwald 
64*036e1007SMatthias Ringwald     hxcmod_setcfg(&mod_context, 44100, 1, 1);
65f8903005SMatthias Ringwald     hxcmod_load(&mod_context, (void *) &mod_data, mod_len);
66f8903005SMatthias Ringwald 
67f8903005SMatthias Ringwald     // setup audio playback
68d365bb51SMatthias Ringwald     const btstack_audio_sink_t * audio = btstack_audio_sink_get_instance();
69f8903005SMatthias Ringwald     if (!audio){
70d365bb51SMatthias Ringwald         printf("BTstack Audio Sink not setup\n");
71f8903005SMatthias Ringwald         return 10;
72f8903005SMatthias Ringwald     }
73d365bb51SMatthias Ringwald     audio->init(2, 44100, &audio_playback);
74f8903005SMatthias Ringwald     audio->start_stream();
75f8903005SMatthias Ringwald 
76f8903005SMatthias Ringwald     return 0;
77f8903005SMatthias Ringwald }
78ec8ae085SMilanka Ringwald 
79ec8ae085SMilanka Ringwald /* EXAMPLE_END */
80