~mkas/mixxx/mysql

« back to all changes in this revision

Viewing changes to mixxx/lib/xwax/timecoder.h

  • Committer: MKas
  • Date: 2012-11-03 12:55:54 UTC
  • Revision ID: mkas@tux.lt-20121103125554-ez5ajqyk7bwehrp2
merge with trunk + sql fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * Copyright (C) 2010 Mark Hills <mark@pogo.org.uk>
 
1
/*
 
2
 * Copyright (C) 2012 Mark Hills <mark@pogo.org.uk>
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
6
6
 * version 2, as published by the Free Software Foundation.
7
 
 * 
 
7
 *
8
8
 * This program is distributed in the hope that it will be useful, but
9
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
11
 * General Public License version 2 for more details.
12
 
 * 
 
12
 *
13
13
 * You should have received a copy of the GNU General Public License
14
14
 * version 2 along with this program; if not, write to the Free
15
15
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24
24
#include <stdbool.h>
25
25
#endif
26
26
 
27
 
/* #include "device.h" */
28
27
#include "lut.h"
29
28
#include "pitch.h"
30
29
 
31
30
#define TIMECODER_CHANNELS 2
32
31
 
33
 
 
34
32
typedef unsigned int bits_t;
35
33
 
36
 
 
37
 
struct timecode_def_t {
 
34
struct timecode_def {
38
35
    char *name, *desc;
39
36
    int bits, /* number of bits in string */
40
37
        resolution, /* wave cycles per second */
44
41
    unsigned int length, /* in cycles */
45
42
        safe; /* last 'safe' timecode number (for auto disconnect) */
46
43
    bool lookup; /* true if lut has been generated */
47
 
    struct lut_t lut;
 
44
    struct lut lut;
48
45
};
49
46
 
50
 
 
51
 
struct timecoder_channel_t {
52
 
    int positive, /* wave is in positive part of cycle */
 
47
struct timecoder_channel {
 
48
    bool positive, /* wave is in positive part of cycle */
53
49
        swapped; /* wave recently swapped polarity */
54
50
    signed int zero;
55
51
    unsigned int crossing_ticker; /* samples since we last crossed zero */
56
52
};
57
53
 
58
 
 
59
 
struct timecoder_t {
60
 
    struct timecode_def_t *def;
 
54
struct timecoder {
 
55
    struct timecode_def *def;
61
56
    double speed;
62
57
 
63
58
    /* Precomputed values */
64
59
 
65
 
    float dt, zero_alpha;
 
60
    double dt, zero_alpha;
66
61
 
67
62
    /* Pitch information */
68
63
 
69
 
    int forwards;
70
 
    struct timecoder_channel_t primary, secondary;
71
 
    struct pitch_t pitch;
 
64
    bool forwards;
 
65
    struct timecoder_channel primary, secondary;
 
66
    struct pitch pitch;
72
67
 
73
68
    /* Numerical timecode */
74
69
 
84
79
    int mon_size, mon_counter;
85
80
};
86
81
 
87
 
 
 
82
struct timecode_def* timecoder_find_definition(const char *name);
88
83
void timecoder_free_lookup(void);
89
84
 
90
 
int timecoder_init(struct timecoder_t *tc, const char *def_name, double speed,
91
 
                   unsigned int sample_rate);
92
 
void timecoder_clear(struct timecoder_t *tc);
93
 
 
94
 
int timecoder_monitor_init(struct timecoder_t *tc, int size);
95
 
void timecoder_monitor_clear(struct timecoder_t *tc);
96
 
 
97
 
void timecoder_submit(struct timecoder_t *tc, const signed short *pcm, size_t npcm);
98
 
 
99
 
signed int timecoder_get_position(struct timecoder_t *tc, float *when);
100
 
 
101
 
 
102
 
/* Return the pitch relative to reference playback speed */
103
 
 
104
 
static inline float timecoder_get_pitch(struct timecoder_t *tc)
 
85
void timecoder_init(struct timecoder *tc, struct timecode_def *def,
 
86
                    double speed, unsigned int sample_rate);
 
87
void timecoder_clear(struct timecoder *tc);
 
88
 
 
89
int timecoder_monitor_init(struct timecoder *tc, int size);
 
90
void timecoder_monitor_clear(struct timecoder *tc);
 
91
 
 
92
void timecoder_cycle_definition(struct timecoder *tc);
 
93
void timecoder_submit(struct timecoder *tc, const signed short *pcm, size_t npcm);
 
94
signed int timecoder_get_position(struct timecoder *tc, double *when);
 
95
 
 
96
/*
 
97
 * The timecode definition currently in use by this decoder
 
98
 */
 
99
 
 
100
static inline struct timecode_def* timecoder_get_definition(struct timecoder *tc)
 
101
{
 
102
    return tc->def;
 
103
}
 
104
 
 
105
/*
 
106
 * Return the pitch relative to reference playback speed
 
107
 */
 
108
 
 
109
static inline double timecoder_get_pitch(struct timecoder *tc)
105
110
{
106
111
    return pitch_current(&tc->pitch) / tc->speed;
107
112
}
108
113
 
109
 
 
110
 
/* The last 'safe' timecode value on the record. Beyond this value, we
 
114
/*
 
115
 * The last 'safe' timecode value on the record. Beyond this value, we
111
116
 * probably want to ignore the timecode values, as we will hit the
112
 
 * label of the record. */
 
117
 * label of the record.
 
118
 */
113
119
 
114
 
static inline unsigned int timecoder_get_safe(struct timecoder_t *tc)
 
120
static inline unsigned int timecoder_get_safe(struct timecoder *tc)
115
121
{
116
 
    return tc->def->safe * 1000 / (tc->def->resolution * tc->speed);
 
122
    return tc->def->safe;
117
123
}
118
124
 
119
 
 
120
 
/* The resolution of the timecode. This is the number of bits per
121
 
 * second at reference playback speed */
122
 
 
123
 
static inline double timecoder_get_resolution(struct timecoder_t *tc)
 
125
/*
 
126
 * The resolution of the timecode. This is the number of bits per
 
127
 * second at reference playback speed
 
128
 */
 
129
 
 
130
static inline double timecoder_get_resolution(struct timecoder *tc)
124
131
{
125
132
    return tc->def->resolution * tc->speed;
126
133
}
127
134
 
128
 
 
129
 
/* The number of revolutions per second of the timecode vinyl,
130
 
 * used only for visual display */
131
 
 
132
 
static inline double timecoder_revs_per_sec(struct timecoder_t *tc)
 
135
/*
 
136
 * The number of revolutions per second of the timecode vinyl,
 
137
 * used only for visual display
 
138
 */
 
139
 
 
140
static inline double timecoder_revs_per_sec(struct timecoder *tc)
133
141
{
134
142
    return (33.0 + 1.0 / 3) * tc->speed / 60;
135
143
}