Skip to content
Newer
Older
100644 151 lines (116 sloc) 5.44 KB
efc5211 @drowaudio New class, AudioSampleBufferAudioFormat.
authored Mar 17, 2012
1 /*
2 ==============================================================================
3
4 This file is part of the dRowAudio JUCE module
5 Copyright 2004-12 by dRowAudio.
6
7 ------------------------------------------------------------------------------
8
9 dRowAudio can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the module distribution, or can be found
12 online at www.gnu.org/licenses.
13
14 dRowAudio is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18 ==============================================================================
19 */
20
af3759b @drowaudio Moved the library into the grow namespace.
authored May 1, 2012
21
efc5211 @drowaudio New class, AudioSampleBufferAudioFormat.
authored Mar 17, 2012
22
23 //==============================================================================
24 namespace
25 {
26 const char* const audioSampleBufferAudioFormatName = "AudioSampleBuffer format stream";
27 }
28
29 //==============================================================================
30 class AudioSampleBufferReader : public AudioFormatReader
31 {
32 public:
33 AudioSampleBufferReader (InputStream* const inp)
34 : AudioFormatReader (inp, TRANS (audioSampleBufferAudioFormatName)),
35 ok (false)
36 {
37 usesFloatingPointData = true;
38
39 if (inp != nullptr)
40 {
41 ok = isAudioSampleBuffer (*inp, numChannels, lengthInSamples);
42 sampleRate = 44100;
43 bitsPerSample = 32;
44 }
45 }
46
47 ~AudioSampleBufferReader()
48 {
49 }
50
51 //==============================================================================
52 bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
53 int64 startSampleInFile, int numSamples)
54 {
55 jassert (destSamples != nullptr);
56 const int64 samplesAvailable = lengthInSamples - startSampleInFile;
57
58 if (samplesAvailable < numSamples)
59 {
60 for (int i = numDestChannels; --i >= 0;)
61 if (destSamples[i] != nullptr)
62 zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
63
64 numSamples = (int) samplesAvailable;
65 }
66
67 if (numSamples <= 0)
68 return true;
69
70 while (numSamples > 0)
71 {
72 const int numThisTime = jmin (8192, numSamples);
73 const int numBytes = numThisTime * sizeof (float);
74
3192ad7 @drowaudio Fixed a filename bug in Windows. Cleaned up some MSVC warnings.
authored May 15, 2012
75 for (int c = (int) numChannels; --c >= 0;)
efc5211 @drowaudio New class, AudioSampleBufferAudioFormat.
authored Mar 17, 2012
76 {
77 const int64 pos = sampleToReadPosition (c, startSampleInFile);
78 input->setPosition (pos);
79
80 if (destSamples[c] != nullptr)
81 {
3192ad7 @drowaudio Fixed a filename bug in Windows. Cleaned up some MSVC warnings.
authored May 15, 2012
82 if (c < (int) numChannels)
efc5211 @drowaudio New class, AudioSampleBufferAudioFormat.
authored Mar 17, 2012
83 input->read (destSamples[c] + startOffsetInDestBuffer, numBytes);
84 else
85 zeromem (destSamples[c] + startOffsetInDestBuffer, numBytes);
86 }
87 }
88
89 startOffsetInDestBuffer += numThisTime;
90 numSamples -= numThisTime;
91 }
92
93 return true;
94 }
95
96 bool ok;
97
98 private:
99 int64 sampleToReadPosition (int channel, int64 samplePosition)
100 {
101 const size_t startPosition = (numChannels + 1) * sizeof (float*);
102 const int64 channelStartByte = startPosition + (channel * lengthInSamples * sizeof (float));
103 const int64 sampleStartByte = channelStartByte + (samplePosition * sizeof (float));
104
105 return sampleStartByte;
106 }
107
108 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSampleBufferReader);
109 };
110
111 //==============================================================================
112 AudioSampleBufferAudioFormat::AudioSampleBufferAudioFormat()
113 : AudioFormat (TRANS (audioSampleBufferAudioFormatName), StringArray())
114 {
115 }
116
117 AudioSampleBufferAudioFormat::~AudioSampleBufferAudioFormat() {}
118
119 Array<int> AudioSampleBufferAudioFormat::getPossibleSampleRates() { return Array<int>(); }
120 Array<int> AudioSampleBufferAudioFormat::getPossibleBitDepths() { return Array<int>(); }
121
122 bool AudioSampleBufferAudioFormat::canDoStereo() { return true; }
123 bool AudioSampleBufferAudioFormat::canDoMono() { return true; }
124
125 //==============================================================================
126 AudioFormatReader* AudioSampleBufferAudioFormat::createReaderFor (InputStream* sourceStream,
127 bool deleteStreamIfOpeningFails)
128 {
129 ScopedPointer<AudioSampleBufferReader> r (new AudioSampleBufferReader (sourceStream));
130
131 if (r->ok)
132 return r.release();
133
134 if (! deleteStreamIfOpeningFails)
135 r->input = nullptr;
136
137 return nullptr;
138 }
139
ca21037 @drowaudio Updated the demo app. Fixed some MSVC compiler warnings.
authored May 15, 2012
140 AudioFormatWriter* AudioSampleBufferAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
141 double /*sampleRateToUse*/,
142 unsigned int /*numberOfChannels*/,
143 int /*bitsPerSample*/,
144 const StringPairArray& /*metadataValues*/,
145 int /*qualityOptionIndex*/)
efc5211 @drowaudio New class, AudioSampleBufferAudioFormat.
authored Mar 17, 2012
146 {
147 jassertfalse; // not yet implemented!
148 return nullptr;
149 }
150
Something went wrong with that request. Please try again.