v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
asset/audio.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * Sifteo SDK
4  *
5  * Copyright <c> 2012 Sifteo, Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #pragma once
27 
28 /*
29  * This header needs to work in both userspace and non-userspace builds.
30  */
31 
32 #include <sifteo/abi.h>
33 
34 namespace Sifteo {
35 
50 struct AssetAudio {
51  _SYSAudioModule sys;
52 
58  unsigned speed() const {
59  return sys.sampleRate;
60  }
61 
74  static AssetAudio fromPCM(const int16_t *samples, unsigned numSamples)
75  {
76  const AssetAudio result = {{
77  /* sampleRate */ 0,
78  /* loopStart */ 0,
79  /* loopEnd */ numSamples,
80  /* loopType */ _SYS_LOOP_REPEAT,
81  /* type */ _SYS_PCM,
82  /* volume */ _SYS_AUDIO_DEFAULT_VOLUME,
83  /* dataSize */ numSamples * sizeof samples[0],
84  /* pData */ reinterpret_cast<uintptr_t>(samples),
85  }};
86  return result;
87  }
88 
90  template <typename T>
91  static AssetAudio fromPCM(const T &samples) {
92  return fromPCM(&samples[0], arraysize(samples));
93  }
94 };
95 
112 struct AssetTracker {
113  _SYSXMSong song;
114 
116  unsigned numChannels() const {
117  return song.nChannels;
118  }
119 
121  unsigned numPatterns() const {
122  return song.nPatterns;
123  }
124 
126  unsigned numInstruments() const {
127  return song.nInstruments;
128  }
129 
131  unsigned tempo() const {
132  return song.tempo;
133  }
134 
136  unsigned bpm() const {
137  return song.bpm;
138  }
139 };
140 
145 }; // namespace Sifteo
unsigned numPatterns() const
The number of patterns in this tracker module.
Definition: asset/audio.h:121
unsigned speed() const
Return the default speed for this audio asset, in samples per second.
Definition: asset/audio.h:58
unsigned numInstruments() const
The number of instruments in this tracker module.
Definition: asset/audio.h:126
static AssetAudio fromPCM(const T &samples)
Templatized version of fromPCM(), for fixed-size sample arrays.
Definition: asset/audio.h:91
#define arraysize(a)
Definition: macros.h:362
A Tracker module, converted from XM format by stir
Definition: asset/audio.h:112
An audio asset, using any supported compression codec.
Definition: asset/audio.h:50
Definition: array.h:34
unsigned numChannels() const
The number of channels used by this tracker module.
Definition: asset/audio.h:116
unsigned tempo() const
This tracker module's default tempo (ticks)
Definition: asset/audio.h:131
unsigned bpm() const
This tracker module's default beats per minute (notes)
Definition: asset/audio.h:136
static AssetAudio fromPCM(const int16_t *samples, unsigned numSamples)
Create an AssetAudio object programmatically, from uncompressed PCM data.
Definition: asset/audio.h:74