rev: a97c687f9dcba7b00e98057cc13a698003d6016d rubberband-ios-test/rubberbandtest/ViewController.mm -rw-r--r-- 1.8 KiB View raw Log this file
a97c687f9dcb — Chris Cannam Do some timing calculations 4 years ago
                                                                                
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
//  ViewController.m
//  rubberbandtest
//
//  Created by Chris Cannam on 09/12/2014.
//  Copyright (c) 2014 Breakfast Quay. All rights reserved.
//

#import "ViewController.h"

#include "rubberband/RubberBandStretcher.h"

#include <iostream>

#include <sys/time.h>

using std::cerr;
using std::endl;

using namespace RubberBand;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    RubberBandStretcher stretcher(44100, 1);
    stretcher.setTimeRatio(1.2);
    stretcher.setPitchScale(1.02);
    
    timeval tv;
    (void)gettimeofday(&tv, 0);

    int countIn = 0, countOut = 0;
    
    int n = 10000;
    for (int i = 0; i < n; ++i) {
        float *buffer = new float[1024];
        for (int j = 0; j < 1024; ++j) {
            buffer[j] = drand48();
        }
        stretcher.process(&buffer, 1024, i == n-1);
        countIn += 1024;
        delete[] buffer;
        int avail = 0;
        while ((avail = stretcher.available()) > 0) {
            countOut += avail;
            float *out = new float[avail];
            stretcher.retrieve(&out, avail);
            delete[] out;
        }
    }

    timeval etv;
    (void)gettimeofday(&etv, 0);
    
    etv.tv_sec -= tv.tv_sec;
    if (etv.tv_usec < tv.tv_usec) {
        etv.tv_usec += 1000000;
        etv.tv_sec -= 1;
    }
    etv.tv_usec -= tv.tv_usec;
    
    double sec = double(etv.tv_sec) + (double(etv.tv_usec) / 1000000.0);
    cerr << "elapsed time: " << sec << " sec, in frames/sec: " << countIn/sec << ", out frames/sec: " << countOut/sec << endl;

    exit(0);
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end