| 1 |
/* |
|---|
| 2 |
* Sweep, a sound wave editor. |
|---|
| 3 |
* |
|---|
| 4 |
* Copyright (C) 2000 Conrad Parker |
|---|
| 5 |
* |
|---|
| 6 |
* This program is free software; you can redistribute it and/or modify |
|---|
| 7 |
* it under the terms of the GNU General Public License as published by |
|---|
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 |
* (at your option) any later version. |
|---|
| 10 |
* |
|---|
| 11 |
* This program is distributed in the hope that it will be useful, |
|---|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 |
* GNU General Public License for more details. |
|---|
| 15 |
* |
|---|
| 16 |
* You should have received a copy of the GNU General Public License |
|---|
| 17 |
* along with this program; if not, write to the Free Software |
|---|
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 |
*/ |
|---|
| 20 |
|
|---|
| 21 |
#ifdef HAVE_CONFIG_H |
|---|
| 22 |
# include <config.h> |
|---|
| 23 |
#endif |
|---|
| 24 |
|
|---|
| 25 |
#include <stdio.h> |
|---|
| 26 |
#include <string.h> |
|---|
| 27 |
#include <glib.h> |
|---|
| 28 |
|
|---|
| 29 |
#include <sweep/sweep_types.h> |
|---|
| 30 |
|
|---|
| 31 |
/* |
|---|
| 32 |
* Determine the number of samples occupied by a number of frames |
|---|
| 33 |
* in a given format. |
|---|
| 34 |
*/ |
|---|
| 35 |
glong |
|---|
| 36 |
frames_to_samples (sw_format * format, sw_framecount_t nr_frames) |
|---|
| 37 |
{ |
|---|
| 38 |
return (nr_frames * (glong)format->channels); |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
/* |
|---|
| 42 |
* Determine the size in bytes of a number of frames of a given format. |
|---|
| 43 |
*/ |
|---|
| 44 |
glong |
|---|
| 45 |
frames_to_bytes (sw_format * format, sw_framecount_t nr_frames) |
|---|
| 46 |
{ |
|---|
| 47 |
return (nr_frames * (glong)format->channels * sizeof(sw_audio_t)); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
/* |
|---|
| 51 |
* Convert a number of frames to seconds |
|---|
| 52 |
*/ |
|---|
| 53 |
sw_time_t |
|---|
| 54 |
frames_to_time (sw_format * format, sw_framecount_t nr_frames) |
|---|
| 55 |
{ |
|---|
| 56 |
return ((gfloat)nr_frames / (gfloat)format->rate); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
/* |
|---|
| 60 |
* Convert seconds to frames |
|---|
| 61 |
*/ |
|---|
| 62 |
sw_framecount_t |
|---|
| 63 |
time_to_frames (sw_format * format, sw_time_t time) |
|---|
| 64 |
{ |
|---|
| 65 |
return ((sw_framecount_t)((sw_time_t)format->rate * time)); |
|---|
| 66 |
} |
|---|