Hi,
this is the first time I try to build an iOS app. I started from the provided example AudioAppExample.
I am trying to set the block size using
juce::AudioDeviceManager::AudioDeviceSetup result;
deviceManager.getAudioDeviceSetup(result);
result.bufferSize = 256; //this line does not have any effect
deviceManager.setAudioDeviceSetup(result, true);
but calling it in the MainComponent() constructor or in prepareToPlay() has no effect and the block size defaults to 1156. In fact, at those points in the code, deviceManager.getAudioDeviceSetup(result).bufferSize is 0.
Where is the appropriate point in which to call setAudioDeviceSetup(result, true); so that it actually affects the blocksize?
Using the latest master from Juce, and targeting an iPad mini retina running iOs 8.0.2
Thanks,
Giulio
Full code of my MainComponent.cpp is below
/*
==============================================================================
This file was auto-generated!
==============================================================================
*/
#ifndef MAINCOMPONENT_H_INCLUDED
#define MAINCOMPONENT_H_INCLUDED
#include "../JuceLibraryCode/JuceHeader.h"
//==============================================================================
class MainContentComponent : public AudioAppComponent
{
public:
//==============================================================================
MainContentComponent()
: lineLength (0.05*44100),
currentLine (0),
sampleRate (0.0),
expectedSamplesPerBlock (0)
{
setSize (800, 600);
// specify the number of input and output channels that we want to open
setAudioChannels (0, 2);
juce::AudioDeviceManager::AudioDeviceSetup result;
deviceManager.getAudioDeviceSetup(result);
result.bufferSize = 256; //this line does not have any effect
deviceManager.setAudioDeviceSetup(result, true);
}
~MainContentComponent()
{
shutdownAudio();
}
//==============================================================================
void prepareToPlay (int samplesPerBlockExpected, double newSampleRate) override
{
sampleRate = newSampleRate;
expectedSamplesPerBlock = samplesPerBlockExpected;
}
/* This method generates the actual audio samples.
In this example the buffer is filled with a sine wave whose frequency and
amplitude are controlled by the mouse position.
*/
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
{
bufferToFill.clearActiveBufferRegion();
for (int chan = 0; chan < bufferToFill.buffer->getNumChannels(); ++chan)
{
float* const channelData = bufferToFill.buffer->getWritePointer (chan, bufferToFill.startSample);
for (int i = 0; i < bufferToFill.numSamples ; ++i)
{
if(currentLine>0){
channelData[i] = (currentLine--)/(float)lineLength;
}
}
}
}
void releaseResources() override
{
// This gets automatically called when audio device parameters change
// or device is restarted.
}
//==============================================================================
void paint (Graphics& g) override
{
// (Our component is opaque, so we must completely fill the background with a solid colour)
g.fillAll (Colours::black);
juce::AudioDeviceManager::AudioDeviceSetup result;
deviceManager.getAudioDeviceSetup(result);
g.setColour (Colours::lightgreen);
String blockSize;
blockSize << "Current block size: " << result.bufferSize << "\n";
g.drawText(blockSize, 200, 100, 300, 200, 1);
g.setColour (Colours::grey);
}
// Mouse handling..
void mouseDown (const MouseEvent& e) override
{
if(currentLine == 0){
currentLine = lineLength;
}
}
void mouseDrag (const MouseEvent& e) override
{
}
void mouseUp (const MouseEvent&) override
{
repaint();
}
void resized() override
{
// This is called when the MainContentComponent is resized.
// If you add any child components, this is where you should
// update their positions.
}
private:
//==============================================================================
int lineLength;
int currentLine;
double sampleRate;
int expectedSamplesPerBlock;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};
Component* createMainContentComponent() { return new MainContentComponent(); };
#endif // MAINCOMPONENT_H_INCLUDED