Newbie Working on a Numerical Conversion File

Hey there everyone! I'm a newbie here, just started coding with C++ a few weeks ago since we started learning about it in lecture. I've been doing a few side projects (which are in no way associated with the class work) to try and get a better understanding of what I'm doing.

So I'm currently working on a program to help you convert a .brstm to a .hps file. These are audio files for video games so it's a pretty obscure subject. Luckily what I'm doing isn't too difficult. Here's the breakdown - We're trying to find 4 values by converting a series of values. The four values we're looking for are (1) loopStart (where the loop of a song begins), (2) Blocks (amount of data required to store files), (3) BlockStart (Block on which the song begins it's loop), and (4) BlockLoop (the Block on which the song ends the loop). The calculations to find these are all really simple.

LoopStart = Loop Start Sample/Sample Rate (show at least 3 decimal places)

Blocks = Song Length/0.448 Rounded up to next value. (ex: if song length/.448 = 298.001 it would need to result as 299)

BlockStart = Blocks - 1 (int value)

BlockLoop = Blocks - BlockStart - 1 (int value)

So it's all really easy. The only ones I really need help with is the calculation for Blocks and the decimal placement for the result of LoopStart. I've been messing around with float and int and all that but can't seem to figure out how to get Blocks to round up properly. (Code is shown below). The other reason I told you guys ALL of that information even though I only need help with one little thing is because I want to know what else I could change in my code to make it more efficient/professional. I'm working hard to learn this language to the fullest so all extra help is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <iomanip>
using namespace std;

int end1;
int Blocks;
int BlockLoop;
int BlockStart;
float LoopStart;
float SampleRate;
float NumSamples;
float LoopStartSample;

int main()
{
    //INFO FOR LOOPSTART
    cout << "Enter the Loop Start Sample: ";
    cin >> LoopStartSample;
    cout << "Enter the SampleRate: ";
    cin >> SampleRate;

    //INFO FOR LOOPSTART
    cout << "Enter the NumSamples: ";
    cin >> NumSamples;

    //INFO FOR BLOCKSTART
    cout << "Enter the BlockLoop: ";
    cin >> BlockLoop;

    LoopStart = LoopStartSample/SampleRate;
    Blocks = (NumSamples/32000)/0.448;
    BlockStart = BlockLoop - 1;
    BlockLoop = ((Blocks - BlockStart) - 1);

    cout << endl;
    cout << "The Loop Start value is: " << setprecision(5) << LoopStart << endl;
    cout << "The number of blocks required is: " << Blocks+1 << endl;
    cout << "The Block Start value is: " << BlockStart << endl;
    cout << "The Block Loop value is: " << BlockLoop << endl;
    cout << endl;
    cout << "Type end and press enter to quit.";    //PROGAM CLOSES IMMEDIATELY AFTER THE ABOVE HAVE PRINTED
    cin >> end1;                                    //WITH THESE EXTRA LINES IT STAYS OPEN UNTIL USER TELLS IT TO QUIT
    return 0;  
}


Few other minor questions...when I run the .exe of this and I put in all of the information, it closes like right away so you can't even see the resultant values so I added the last to instances of cout and cin. What's a better way to go about fixing that problem? Also, is 'return 0;' necessary or would the code work without it? And finally, should I split this up into multiple functions or is this just as efficient? Thank you to everyone who offers help in advance.
Last edited on
closed account (48T7M4Gy)
when I run the .exe of this ...


You're not supposed to but make system("pause"); the second to last line of main.
Last edited on
Why exactly aren't you supposed to do it, and what are the consequences of doing it?
closed account (48T7M4Gy)
If it works do it. It's a bit like the use of using namespace std; Ideally you shouldn't use that either but it is an expedient for students or if you are russhed rather than producing good robust software.

You can look up the reasons why they are not preferred but as long as you are aware of it there's no great comeback if you do.

Another way is to open the command console in the .exe directory and run it from there. In that situation you don't need to have anything.

http://stackoverflow.com/questions/1107705/systempause-why-is-it-wrong
Topic archived. No new replies allowed.