ios 8.1 calling AudioConvertFillComplexBuffer make a infinite loop with cpuload 100% - infinite-loop

I'm converting audio by using the AudioToolBox.AudioConverter library.
AudioStreamBasicDescription inDescription;
inDescription.mSampleRate = 44100;
inDescription.mFormatID = kAudioFormatMPEGLayer3;
inDescription.mFormatFlags = 0;
inDescription.mBytesPerPacket = 0;
inDescription.mFramesPerPacket = 1152;
inDescription.mBytesPerFrame = 0;
inDescription.mChannelsPerFrame = 2;
inDescription.mBitsPerChannel = 0;
inDescription.mReserved = 0;
AudioStreamBasicDescription outDescription;
audioDescription.mFormatID = kAudioFormatLinearPCM
audioDescription.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian;
audioDescription.mChannelsPerFrame = 2;
audioDescription.mBytesPerPacket = sizeof(SInt16)*audioDescription.mChannelsPerFrame;
audioDescription.mFramesPerPacket = 1;
audioDescription.mBytesPerFrame = sizeof(SInt16)*audioDescription.mChannelsPerFrame;
audioDescription.mBitsPerChannel = 8 * sizeof(SInt16);
audioDescription.mSampleRate = 44100.0;
This is the conversion part with mp3AudioData...
AudioBufferList *mp3Audio = (AudioBufferList *)malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer));
mp3Audio->mNumberBuffers = 1;
mp3Audio->mBuffers[0].mNumberChannels = 2;
mp3Audio->mBuffers[0].mDataByteSize = chunkLen;
mp3Audio->mBuffers[0].mData = calloc(chunkLen, sizeof(uint8_t));
memcpy(mp3Audio->mBuffers[0].mData, chunkData, chunkLen);
AudioStreamPacketDescription *packetDescription =
(AudioStreamPacketDescription*)malloc(sizeof(AudioStreamPacketDescription) * frames);
packetDescription->mDataByteSize = chunkLen;
packetDescription->mStartOffset = 0;
packetDescription->mVariableFramesInPacket = 1;
OSStatus result = AudioConverterFillComplexBuffer(audioConverter,
fillComplexBufferInputProc,
&(struct fillComplexBufferInputProc_t) { .bufferList =mp3Audio, .frames = frames, .packetDescriptions = packetDescription },
&frames,
pcmAudio,
NULL);
free(mp3Audio->mBuffers[0].mData);
free(mp3Audio);
free(packetDescription);
The first running of AudioConverterFillComplexBuffer is OK but when I run that function a second time, the infinite loop happens with cpuload 100%.
This code is OK on an IOS 7 device, but when I run it on an IOS 8 device, the infinite loop happens.
Could anyone tell me why this happens on IOS 8?
fillComplexBufferInputProc function:
static OSStatus fillComplexBufferInputProc(AudioConverterRef inAudioConverter,
UInt32 *ioNumberDataPackets,
AudioBufferList *ioData,
AudioStreamPacketDescription **outDataPacketDescription,
void *inUserData) {
struct fillComplexBufferInputProc_t *arg = inUserData;
for (int i = 0; i < ioData->mNumberBuffers; i++) {
ioData->mBuffers[i].mData = arg->bufferList->mBuffers[i].mData;
ioData->mBuffers[i].mDataByteSize = arg->bufferList->mBuffers[i].mDataByteSize;
}
if (NULL == *outDataPacketDescription) {
*outDataPacketDescription = arg->packetDescriptions;
}
*ioNumberDataPackets = arg->frames;
return noErr;
}

Because it seems no possible infinite loop in your code (except for-loop in fillComplexBufferInputProc function), I suggest you use Instruments (Time Profiler) to see what method is using the majority of CPU time. Check the stack trace for more information, so maybe we can help. Here is a tutorial for time profiler.

Related

Projectiles In Gamemaker Studio 2 Not Moving

My gun's begin step code:
if (global.night == true) {
image_angle = point_direction(x, y, mouse_x, mouse_y);
image_index = 1;
alarm[0] = 0.5 * room_speed;
firingdelay -= 1;
if (mouse_check_button_pressed(mb_left)) && (firingdelay < 0) {
firingdelay = 10;
with (instance_create_layer(Revolver.x+12, Revolver.y, "Bullets", Bullet)) {
direction = Revolver.image_angle;
speed = 25;
image_angle = direction;
}
}
}
It creates the bullets, but they don't move. Can anyone help?
If you have physics enabled in a room, the regular speed and direction variables will not work. Do you have physics enabled? The code looks fine.

Which is more efficient in OpenCL: if conditions or for loops?

I have a piece of OpenCL code like this
if (Sum[0] < Best)
{
Best = Sum[0];
iBest = 1;
*aBits = Bits[0];
}
if (Sum[1] < Best)
{
Best = Sum[1];
iBest = 2;
*aBits = Bits[1];
}
if (Sum[2] < Best)
{
Best = Sum[2];
iBest = 3;
*aBits = Bits[2];
}
if (Sum[3] < Best)
{
Best = Sum[3];
iBest = 4;
*aBits = Bits[3];
}
if (Sum[4] < Best)
{
Best = Sum[4];
iBest = 5;
*aBits = Bits[4];
}
if (Sum[5] < Best)
{
Best = Sum[5];
iBest = 6;
*aBits = Bits[5];
}
if (Sum[6] < Best)
{
Best = Sum[6];
iBest = 7;
*aBits = Bits[6];
}
if (Sum[7] < Best)
{
Best = Sum[7];
iBest = 8;
*aBits = Bits[7];
}
In order to reduce the logic, I rewrote the code like this
for(i = 1; i < 8; i++)
{
if(Sum[i] < Sum[index])
index = i;
}
if (Sum[index] < Best)
{
Best = Sum[index];
iBest = index + 1;
*aBits = Bits[index];
}
But, in the second case the latency increased, by about 20%. Can anybody provide any insight into this kind of behavior? Is the if conditions style of coding more efficient than for loops in OpenCL?
I'm using Intel 530 (Gen9) GPU. I'm using memory mapped access.
The first case is bad for a GPU. Since it forces that when one of the work items enters an if condition all of them do.
If you expect random entering the "if" conditions, in the end all instructions are executed and they are more than in the second case.
While on the second case, the GPU instructions inside the "if" are less, only one liners. And all the work items enter the last section at the same time.
For a CPU the first case is best, since there is no need to save an index and then look it up.
In any case, avoid double/tripple reading variables on the global memory. Because those are not optimized by the compiler (unless marked as read_only). This code should be much faster to what you wrote:
int best_sum = Sum[index]; //Private, fast access
for(i = 1; i < 8; i++)
{
int sum = Sum[i]; //Again private
if(sum < best_sum){
index = i;
best_sum = sum;
}
}
if (best_sum < Best)
{
Best = best_sum;
iBest = index + 1;
*aBits = Bits[index];
}

KsProperty () returns"The data area passed to a system call is too small" ERROR_INSUFFICIENT_BUFFER while setting camera Zoom value

HRESULT hr = S_OK;
KSPROPERTY ksprop;
ZeroMemory(&ksprop, sizeof(ksprop));
PVOID pData = NULL;
ULONG valueSize = 0;
ULONG dataLength = 0;
KSPROPERTY_CAMERACONTROL_S cameraControl;
ZeroMemory(&cameraControl, sizeof(cameraControl));
ksprop.Set = PROPSETID_VIDCAP_CAMERACONTROL;
ksprop.Id = KSPROPERTY_CAMERACONTROL_ZOOM;
ksprop.Flags = KSPROPERTY_TYPE_SET;
cameraControl.Property = ksprop;
cameraControl.Flags = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
cameraControl.Capabilities = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
cameraControl.Value = 50;
pData = &cameraControl;
dataLength = sizeof(cameraControl);
hr = m_pKsControl->KsProperty(
&ksprop, sizeof(ksprop),
pData, dataLength, &valueSize);
here hr "The data area passed to a system call is too small. "
I am compiling on vs 2010 on windows 7 machine.
You are likely to provide a buffer which is too small in fourth parameter.
It's easy to check this out, see IKsControl::KsProperty docs:
To determine the buffer size that is required for a specific property
request, you can call this method with PropertyData set to NULL and
DataLength equal to zero. The method returns
HRESULT_FROM_WIN32(ERROR_MORE_DATA), and BytesReturned contains the
size of the required buffer.
In this KsProperty use case, you should pass KSPROPERTY_CAMERACONTROL_S structure variable to make this work.
For example
KSPROPERTY_CAMERACONTROL_S kspIn = { 0 };
KSPROPERTY_CAMERACONTROL_S kspOut = { 0 };
ULONG valueSize = 0;
kspIn.Property.Set = PROPSETID_VIDCAP_CAMERACONTROL;
kspIn.Property.Id = KSPROPERTY_CAMERACONTROL_ZOOM;
kspIn.Property.Flags = KSPROPERTY_TYPE_SET;
kspOut.Property.Set = PROPSETID_VIDCAP_CAMERACONTROL;
kspOut.Property.Id = KSPROPERTY_CAMERACONTROL_ZOOM;
kspOut.Property.Flags = KSPROPERTY_TYPE_SET;
kspOut.Flags = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
kspOut.Capabilities = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
kspOut.Value = 50;
hr = m_pKsControl->KsProperty(
(PKSPROPERTY)&kspIn, sizeof(kspIn),
&kspOut, sizeof(kspOut), &valueSize);
Should work

ActionScript 2 character selection

I haven't been able to make a character selection in ActionScript 2 so what is an example that, if I click on this button, a movieclip comes out in this frame?
Frame 1:
movieClip1.alpha = 0;
movieClip1.stop();
movieClip2.alpha = 0;
movieClip2.stop();
movieClip3.alpha = 0;
movieClip3.stop();
button1.onPress = function() {
movieClip1.alpha = 100;
movieClip1.play();
}
button2.onPress = function() {
movieClip2.alpha = 100;
movieClip2.play();
}
button3.onPress = function() {
movieClip3.alpha = 100;
movieClip3.play();
}
try something like the below. I haven;t tested this so it prob won;t compile but it'll be very close. Basically put this on a single empty frame on the main timeline. make sure you have button and character movieclips all with export settings and linkage identifiers set. Modify code below and see what happens.
var numButtons:Number = 10; //number of buttons you want
var buttonMovieClipName:String = "button"; //linkage identifier of button
var startX:Number = 10; //start x position
var startY:Number = 500; //start y position
var dist:Number = 10; //distance between buttons
var characters:Array = {"A","B","C","D"}; //linkage names of your characters
var currentChar:MovieClip = null;
for(var i:Number = 0; i < numButtons; i++)
{
this.attachMovie("button", "button"+i, this.getNextHighestDepth());
this["button"+i]._x = startX + (i*(dist+this["button"+i]._width]));
this["button"+i]._y = startY;
this["button"+i].character = characters[i];
this["button"+i].onPress = displayCharacter;
}
function displayCharacter():void
{
var par = this._parent;
//remove previous character on stage
if(currentChar != null)
{
removeMovieClip(par[currentChar]);
}
par.attachMovie(this.character, this.character, par.getNextHighestDepth()); //atach character
par[this.character]._x = 400; //set to whatever
par[this.character]._y = 300; //set to whatever
currentChar = this.character; //set current character to this
}

Bold points in Microsoft Chart control

I'm using microsoft Chart control in my web form. I want points(0, 0) should be bold on the chart. My code is as follows:
DataTable dt = collection.ToDataTable();
// Chart1.Series[0].Points.DataBind(collection, "Price", "OverallQuality", "Label=HotelName");
for (int i = 0; i < dt.Rows.Count; i++)
{
Chart1.Series.Add("series" + i);
Chart1.Series["series" + i].ChartType = SeriesChartType.Point;
// Chart1.Series["series" + i].Points.AddXY(double.Parse(dt.Rows[i]["Price"].ToString()), double.Parse(dt.Rows[i]["OverallQuality"].ToString()));
Chart1.Series["series" + i].Points.AddXY(double.Parse(dt.Rows[i]["OverallQuality"].ToString()), double.Parse(dt.Rows[i]["Price"].ToString()));
Chart1.Series["series" + i].MarkerSize = 10;
Chart1.Series["series" + i].LegendText = dt.Rows[i]["HotelName"].ToString();
}
// Chart1.ChartAreas[0].AxisX.Title = "Price";
// Chart1.ChartAreas[0].AxisY.Title = "Quality";
Chart1.ChartAreas[0].AxisX.Title = "Quality";
Chart1.ChartAreas[0].AxisY.Title = "Price";
Chart1.ChartAreas[0].AxisX.Maximum = 10;
Chart1.ChartAreas[0].AxisX.Minimum = -10;
Chart1.ChartAreas[0].AxisX.Interval = 1;
Chart1.ChartAreas[0].AxisY.Maximum = 10;
Chart1.ChartAreas[0].AxisY.Minimum = -10;
Chart1.ChartAreas[0].AxisY.Interval = 1;
Chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
}
Have you tried changing the PointWidth of the series?
Chart1.Series["series"]["PointWidth"] = "0.2";
You can find a bunch of examples of manipulating this property, such as this. But the trick, for your situation, is dealing with the fact that you can only manipulate this property for the entire series. This post leads me to believe you will have problems setting it for just this particular point, unless you can separate is into it's own somehow. Here's an exmample from stack somewhat similar that might help, depending on how your information is formatted.

Resources