C++ :: Mixer Loop Optimization?

Nov 16, 2014

Can these loops can be optimized?

#define C_SAMPLEPOS(channel) (channel->sound.position)
#define C_BUFFERSIZE(channel) (channel->sound.numsamples)
#define C_BUFFERINC(channel) (channel->bufferinc)
//Use precalculated sample positions!

[Code]....

Should I change the inner loop (checking active channels and if they're valid) to the outer loop?

So the outer loop checks if the channel is valid for use, The inner loop checks and increases the current relsample The inner loop adds the sample to the mixer.

When the outer loop finishes: The outer loop clips all samples.

Would this be faster than the current method? (so instead of a:
for (sample=0;sample<4096;sample++){for (channel=0;channel<66;channel++){/* Process channel here */}}

We get:
for (channel=0;channel<66;channel++){for (sample=0;sample<4096;sample++){/* Process sample */}})

View 1 Replies


ADVERTISEMENT

C :: Port Mixer From OSS To ALSA

Jan 27, 2013

I'm new in c programming and my requirement is as follows. I make a code for oss mixer and now when new systems, throwing the OSS, and there is no /dev/mixer I want to port my code to alsa but my skills are minimal.

Code:
static int mixer_fd = -1, mixer_src = -1;
static char *devices[] = SOUND_DEVICE_NAMES;
int mixer_init(char *mixer_device, char *mixer_source) {
int i;

mixer_src = -1;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
if (strcmp(mixer_source, devices[i]) == 0)

[Code] ....

Coexistance with OSS would be nice, so both could be used depending on users choice. Perhaps: if this first
part of the mixer name is a valid device file, try OSS, otherwise try ALSA?

View 1 Replies View Related

C++ :: Mixer With Wave Files

Mar 11, 2013

I'm doing a mixer with wave files. I can play and even apply the reverse effect to them. the logarithm is like this:

for( unsigned int i=0; i<sampleCount/2; i++ )
{
// swapping with the other half
double temp = samples[i];
samples[i] = samples[sampleCount-i-1];
samples[sampleCount-i-1] = temp;
}

Now I want to apply these effects to the files: delay, slow, and fast but I don't know how to do it. The teacher told me that to do it slow I need to double the Samples so I tried to do this samples[i] = samples[sampleCount*2]; it does not work......Also I apply the contrary to do make the sound fast samples[i] = samples[sampleCount/2]; the samething I don't get the sound desired.

For the daley part I'm thinking on play the audio one without touch it and then repit it 8 times or more to create the delay.... I did it like this:

double temp = samples[i];
samples[i] = samples[sampleCount-i-1]+ (samples[sampleCount -i-1]*8);

It didn't work..why the use of -i-1 after sampleCount!!

View 1 Replies View Related

C++ :: Compiler Optimization And Num Accuracy?

Jun 11, 2014

I could not find anything I could understand on this, so I have heard that -O3 option may reduce the numerical accuracy of doubles. Is this true?

View 11 Replies View Related

Visual C++ :: How To Disable Optimization

Dec 27, 2014

I want to disable optimization in Visual C++ 2010. In gcc on Linux I could just use the -O0 switch, but in Visual C++ 2010 there are two categories of optimizations, one in the C/C++ pane and the other in the Linker pane:

Attachment 33229

So what settings should I choose to make sure that no optimization is being performed?

View 2 Replies View Related

C++ :: Null Statement - Prevent Optimization

Dec 7, 2014

Recently I was looking into embedded programing of AVR microcontrollers.

At this site [URL] ....

I have encounter some code that implements delay

asm volatile ("nop");

From what I understand it is assembler code that creates delay - one processor clock long.

For C/C++ language it should be like ; or {} = null statement.

Now my question is how to implement this C/C++ code and prevent my compiler (WinAVR: AVR-GCC) to delete this command during optimization (-Os or -O2). Or is it simply better to use the assembler function.

I know I can use for-loop

volatile uint8_t foo
for(foo=0; foo<2; ++foo){}

but for that I have to create a variable = wasting 1 byte of RAM; correct?

View 11 Replies View Related

C++ :: Rogue Like Item Creationg And Optimization

Mar 8, 2013

I'm creating a roguelike/ cave exploration game, and I've created a lot of it, but I am having problems with item creation. The item is supposed to be the '*'. I know what the problem is (I'm setting Dmap to map after creating the item, but before outputting Dmap), but I don't know how to fix it.Also, I don't really know how code optimization works.I'll split my code between this post and the comments:

#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time *

[code].....

View 1 Replies View Related

C++ :: Binary Search Tree Optimization?

Jul 9, 2013

I was working on binary tree implementation and came up with this implementation. optimize this code?

/*
Binary Search Tree(BST)
06/27/2013
*/
#include "iostream"

[Code].....

View 3 Replies View Related

C++ :: Metal Cutting Parameter Optimization Program

Apr 3, 2013

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

[Code]....

View 3 Replies View Related

C++ :: Code Review For Empty Base Optimization Pair

Apr 10, 2014

I have tried to implement a much simplified version of boost::compressed_pair.What follows is a partially specialized EBO_pair<T1, T2> class template, written in C++11.The first type T1 is constrained to not be empty.The second type T2 may or may not be empty.

#pragma once
#include <memory>
#include <type_traits>
#include <utility>
namespace dsa
}

[code]...

Edit: added non-member swap() function template.

View 10 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C++ :: How Much Milliseconds To Loop Through For Loop

Feb 20, 2014

Given a for loop:

int i;
for(i = 0; i < 1000; i++)
;

How many nanoseconds, or microseconds or milliseconds does it take for each iteration? And why do some use it as a timer mechanism?

View 3 Replies View Related

C/C++ :: How To Change For Loop Into Do While Loop

Apr 19, 2014

I already made a nested for loop into a while loop (below this) and now I'm trying to make the outer for loop into a do while loop, but it's not working.

#include <iostream>
using namespace std;
int main () {
int len;
int j;
int i;

[Code]....

And I can't make this code do the same thing. It stops after one loop, instead of continuing to the end. Why won't the loops continue?

#include <iostream>
using namespace std;
int main(){
int len;
cout << "Enter a number: ";

[Code] ....

View 2 Replies View Related

C/C++ :: Convert A While Loop To A For Loop?

Mar 25, 2012

I need to convert the following while loop:

count = 1;
while (caloriesForItem != 0, count != numberOfItems )
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
totalCalories += caloriesForItem;
count++;
}

This is what I have come up with:

totalCalories += caloriesForItem;
for (count = 1; caloriesForItem != 0; count != numberOfItems)
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
count++;
cout << "Total calories eaten today = " << totalCalories << endl;
}

However the output is not the same?

View 6 Replies View Related

C# :: Loop Within A Loop?

Sep 25, 2014

I for the life of me can't get my logic straight. I have 2 lists, 1 a list of text, and the other a list of int.

Here's my main list: List<string> ListNeedToADD = ListOfSPSExt.Except(ListOfReportExt).ToList();
Here's my second list:IEnumerable<int> result2 = Enumerable.Range(1, Convert.ToInt32(myValue)).Except(hostList);

I need to loop through my main list, ListNeedToADD, and for each item in that list, grab 1 value from the 2nd list and send those 2 items to a method. Something like this:

foreach (string myString in ListNeedToADD)
{
foreach (var item in result2)
{
intSort = item;
insertReportLimits(attribTable, myString, intSort, con);
}
}

The problem with doing it the way I am above is it loops through ALL the items for each myString.

For my method, it needs to look like this: insertReportLimits(attribTable, "34257", 22, con); then it would move on to the next: insertReportLimits(attribTable, "34854", 27, con); etc etc.

View 4 Replies View Related

C/C++ :: Cannot Get Out Of Loop

Feb 22, 2015

I can't get out of my loop to fill the array. This array should stop and print after 10 inputs. but it keeps asking for input.

This is what my code is supposed to do. Use 0 as sentinel for an array. Only positive ints will be entered into the array. A negative int should result in an error message, then input will continue. The numbers will be inserted into the array in ascending order. Do not insert them then sort the array.

#include <iostream>
#include <cmath>
using namespace std;
const int arraySize =10;

[Code].....

View 4 Replies View Related

C++ :: For Loop To Count Down From 10 To 0

Apr 16, 2013

I am using a for loop to count down from 10 to 0 it's working to count down from 10 to 1 but when the program cames to the 0 then the program freezes by any reason.

Code:
#include <iostream>
using namespace std;
int main()
{
int number[2];
cout << "Enter number: ";
cin >> number[0];
if (number[0] == 1)

[Code] ....

View 11 Replies View Related

C :: Function To End A Loop?

Nov 8, 2013

Is there a way to end a loop ?

Code:
while ( menuopt == 1)
{
printf("Lets start
");
printf("12 x 4 = ?
");

[Code] ....

View 2 Replies View Related

C :: How To Get Rid Of Infinite Loop

Mar 1, 2013

What I need to do to get rid of the infinite loop?

Code:
do {
printf("Enter the number of tests:");
scanf("%d", &test);
if (test< 0 || test> 4)
printf("Wrong number. Please try again!
");
}
while (test< 0 || test>4);

View 9 Replies View Related

C :: Two Repeat One While Loop

Apr 17, 2014

So I have a programming assignment.

Code:
#include <stdio.h>
int main(void)
{
int input;
int sum;
int i;
int t;

[Code] .....

So you input an integer ex) 30

the printing of t =(i+i)+1 and i++ is carried out until i=30, which is when the sum of all the t's is printed.

If the value you entered is not an integer, the loop ends.

I'm supposed to do this with one while loop, and no more. I can't use the for loop either.

How can I do this?

View 7 Replies View Related

C :: Possible To Output By Using Only One Loop

Jul 21, 2013

is it possible to output like this using only one loop? if yes, how?

target output Code: ABCDE

EDCBA here is my code but using one loop im not getting my target output Code: #include <stdio.h>

main()
{
int x, y;

for(x='a', y='e'; x<='e'; x++, y--)
{
printf("%c
%c", x, y);
}
getch();
}

View 6 Replies View Related

C :: While Loop Not Disengaging

Nov 16, 2013

I have a while loop that will not disengage when the input given as "exit".

Code:
while (orders != "exit"){
for (i=0;i<25;i++){
for (j = 0; j<50;j++){
if (i == x && y == j){
printf("H");}
else {
printf("%c", map[i][j]);}

[Code]....

View 1 Replies View Related

C :: Can't Stop While Loop

Dec 6, 2013

I'm trying to create a connect four game, but I've ran into a problem while trying to read valid user input.

Code:

// 4 in a row game
#include <stdio.h>
#include <stdlib.h>
#define NUM_ROWS 6
#define NUM_COLS 7
}

[code]...

If the user enters an invalid number, then it works fine, but if a character is entered, the while loop in main never breaks.

View 9 Replies View Related

C :: Variable In While Loop

Feb 6, 2013

I'm writing a program to sum up the even numbers in between 1 and 100, using a while loop. At the beginning of my program, I initialize a variable "sum" to 0, and a variable "temp" to 1. Afterwards I enter a loop where I determine if "temp" is even or not, and if so add it to sum. However, at the end of my program, when I print "sum", I get a result of 0. Below is my code.

Code:

#include <stdio.h>
int main(void)
{
int sum = 0, temp = 1;
}

[code]...

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved