/*	isAudioDisc
*	checks if selected files are audio files, and greps the playtime of them
*	when all files audio files
*	returns true if audio disc
*/
bool
ProjectTypeSelector::isAudioDisc()
{
	BString *FileType;
	
	for(int i = 0; i < TypeList->CountItems(); i++) {
		FileType = (BString*)TypeList->ItemAt(i);
		if(FileType->Compare("audio", 5) != 0)
			return false;
	}
	
	entry_ref ref;
	BMediaFile *mediaFile;
	bigtime_t time = 0;
	
	for(int i = 0; i < FileList->CountItems(); i++){
		get_ref_for_path(((BString*)FileList->ItemAt(i))->String(), &ref);
		mediaFile = new BMediaFile(&ref);
		BMediaTrack *track = NULL;
		
		for(int j = 0; j < mediaFile->CountTracks(); j++){
			track = mediaFile->TrackAt(j);
			time = track->Duration();
			intPlayTime += ((int)time / 1000000);
		}
		
		delete mediaFile;
	}
		
	return true;
}
Example #2
0
int
main(int argc, char *argv[])
{
	if (argc != 2) {
		fprintf(stderr, "Usage:\n  %s <filename>\n", argv[0]);
		return 1;
	}
	
	entry_ref ref;
	if (get_ref_for_path(argv[1], &ref)!=B_OK)
		return 2;
	BMediaFile *playFile = new BMediaFile(&ref);
	if (playFile->InitCheck()<B_OK) {
		delete playFile;
		return 2;
	}
	
	for (int ix=0; ix<playFile->CountTracks(); ix++) {
		BMediaTrack * track = playFile->TrackAt(ix);
		playFormat.type = B_MEDIA_RAW_AUDIO;
		if ((track->DecodedFormat(&playFormat) == B_OK) 
			&& (playFormat.type == B_MEDIA_RAW_AUDIO)) {
			playTrack = track;
			break;
		}
		if (track)
			playFile->ReleaseTrack(track);
	}
	// Good relations with the Wookiees, I have. 
	signal(SIGINT, keyb_int);

	new BApplication("application/x-vnd.Antares-playfile");
	finished = create_sem(0, "finish wait");
	
	printf("playing file...\n");
	
	// Execute Plan 66!
	sp = new BSoundPlayer(&playFormat.u.raw_audio, "playfile", play_buffer);
	sp->SetVolume(1.0f);

	// Join me, Padmé and together we can rule this galaxy. 
	sp->SetHasData(true);
	sp->Start();

	acquire_sem(finished);

	if (interrupt) {
		// Once more, the Sith will rule the galaxy. 
		printf("interrupted\n");
		sp->Stop();
		kill_thread(reader);
	}

	printf("playback finished\n");

	delete sp;
	delete playFile;
}
Example #3
0
status_t
MainView::LoadWave(const entry_ref& ref)
{
	bigtime_t startLoadWave = system_time();

	fDestCursor = 0;
	fSourceCursor = 0;
	fAverage = 0.0f;
	fAverageCursor = 0;
	fDownsamplingWidth = 0;
	fDownsampleCount = 0;

	// instantiate a BMediaFile object, and make sure there was no error.
	/*BEntry entry("./song.wav");
	entry_ref ref;
	entry.GetRef(&ref);*/
	BMediaFile* mediaFile = new BMediaFile(&ref);
	status_t err = mediaFile->InitCheck();
	if (err != B_OK) {
		printf("cannot contruct BMediaFile object -- %s\n", strerror(err));
		return err;
	}

	for (int32 i = 0; i < mediaFile->CountTracks(); i++) {
		BMediaTrack* track = mediaFile->TrackAt(i);
		if (track == NULL) {
			printf("cannot contruct BMediaTrack object\n");
			return B_ERROR;
		}

		media_format format;
		format.type = B_MEDIA_RAW_AUDIO;
		format.u.raw_audio.format = media_raw_audio_format::B_AUDIO_FLOAT;
		err = track->DecodedFormat(&format);
		if (err != B_OK) {
			printf("BMediaTrack::DecodedFormat error -- %s\n", strerror(err));
			return err;
		}

		if (format.type == B_MEDIA_RAW_AUDIO) {

			// get the actual sourceWindow.left obtained by seeking
			bigtime_t start = system_time();
			int64 actualSeekFrame = fSourceWindow.left;
			err = track->SeekToFrame(&actualSeekFrame);
			if (err != B_OK) {
				printf("BMediaTrack::SeekToFrame(%lli) error -- %s\n", fSourceWindow.left, strerror(err));
				return err;
			}
			printf("BMediaTrack::SeekToFrame(%lli) seekedto=%lli in %llims\n", fSourceWindow.left, actualSeekFrame, (system_time() - start) / 1000);
			fSourceWindow.left = actualSeekFrame;

			frame_range destWindow(0, (uint64) fWaveFrame.Width());
			int64 totalSourceFrameCount = track->CountFrames();
			fDownsamplingWidth = fSourceWindow.Width() / destWindow.Width();

			printf("Source window left=%lli right=%lli width=%lli (total=%lli)\n", fSourceWindow.left, fSourceWindow.right, fSourceWindow.Width(), totalSourceFrameCount);
			printf("Dest window left=%lli right=%lli width=%lli\n", destWindow.left, destWindow.right, destWindow.Width());
			printf("Downsampling width=%lli\n", fDownsamplingWidth);

			delete [] fWave;
			fWave = NULL;
			fWave = new(std::nothrow) float[fSourceWindow.Width() / fDownsamplingWidth]; // ATT: on en prend plus que la largeur de dest car downsampling width entier
			if (fWave == NULL)
				return B_NO_MEMORY;

			char* buffer = new(std::nothrow) char[format.u.raw_audio.buffer_size];
			if (buffer == NULL)
				return B_NO_MEMORY;

			int64 readFrameCount = 0;
			media_header mediaHeader;
			fSourceCursor = fSourceWindow.left;
			for(int64 j = 0; j < fSourceWindow.Width(); j += readFrameCount) {

				err = track->ReadFrames(buffer, &readFrameCount, &mediaHeader);
				if (err) {
					printf("BMediaTrack::ReadFrames error -- %s\n", strerror(err));
					delete [] buffer;
					break;
					// TODO fatal error?
				}

				if (fSourceCursor + readFrameCount >= fSourceWindow.right) {
					readFrameCount = fSourceWindow.right - fSourceCursor;
					printf("yes readFrameCount = %lli\n", readFrameCount);
				}

				_ProcessAudio(buffer, &format, readFrameCount);
			}
			printf("Source cursor %li (read %li)\n", fSourceCursor, fSourceCursor - fSourceWindow.left);
			printf("Dest cursor %li\n", fDestCursor);

			delete [] buffer;
		}

		mediaFile->ReleaseTrack(track);
	}
	delete mediaFile;


	printf("LoadWave in %lims\n", (system_time() - startLoadWave) / 1000 );
	fCurrentEntryRef = ref;
	return B_OK;
}
Example #4
0
void LeftList::MessageReceived(BMessage* msg)
{
	struct AudioInfo fAudioInfo;
	BMediaFile* testfile;
	bool fIsAudio = false;
	BMediaTrack* track;
	media_codec_info codecInfo;
	media_format format;
	memset(&format, 0, sizeof(format));

	entry_ref ref;
	int32 counter = 0;

	switch (msg->what) {

		case B_SIMPLE_DATA:
			while (msg->FindRef("refs", counter++, &ref) == B_OK) {
				if ((testfile = new BMediaFile(&ref)) != NULL) {
					testfile->InitCheck();
					track = testfile->TrackAt(0);
					if (track != NULL) {
						track->EncodedFormat(&format);
						if (format.IsAudio()) {
							memset(&format, 0, sizeof(format));
							format.type = B_MEDIA_RAW_AUDIO;
							track->DecodedFormat(&format);
							fAudioInfo.total_time = track->Duration();
							media_raw_audio_format* raf = &(format.u.raw_audio);
							fAudioInfo.bps = (int32)(raf->format & 0xf);
							fAudioInfo.frame_rate = (int32)raf->frame_rate;
							fAudioInfo.channels = (int32)raf->channel_count;
							track->GetCodecInfo(&codecInfo);
							strcpy(fAudioInfo.pretty_name, codecInfo.pretty_name);
							strcpy(fAudioInfo.short_name, codecInfo.short_name);
							fIsAudio = true;
						}
					}
				} else
					WriteLog("MediaFile NULL (file doesnt exists!?)");

				delete testfile;
				if (fIsAudio) {
					if (!strcmp(fAudioInfo.pretty_name, "Raw Audio") && (fAudioInfo.channels == 2) && (fAudioInfo.frame_rate == 44100) && (fAudioInfo.bps == 2))
						AddItem(new LeftListItem(&ref, ref.name, fAudioBitmap, &fAudioInfo));
					else {
						BAlert* MyAlert = new BAlert("BurnItNow", "You can only burn 16 bits stereo 44.1 kHz Raw Audio files.\n (More audio files will be supported in the future)", "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT);
						MyAlert->Go();
					}
				} else {
					BPath temp_path;
					BEntry(&ref).GetPath(&temp_path);
					jpWindow* win = dynamic_cast<jpWindow*>(Window());
					if (win != NULL)
						win->SetISOFile((char*)temp_path.Path());
				}
			}
			break;
		default:
			BListView::MessageReceived(msg);
			break;
	}
}
Example #5
0
int media_play(const char* uri)
{
	BUrl url;
	entry_ref ref;
	BMediaFile* playFile;

	if (get_ref_for_path(uri, &ref) != B_OK) {
		url.SetUrlString(uri);
		if (url.IsValid()) {
			playFile = new BMediaFile(url);
		} else
			return 2;
	} else
		playFile = new BMediaFile(&ref);

	if (playFile->InitCheck() != B_OK) {
		delete playFile;
		return 2;
	}
	
	for (int i = 0; i < playFile->CountTracks(); i++) {
		BMediaTrack* track = playFile->TrackAt(i);
		playFormat.type = B_MEDIA_RAW_AUDIO;
		if ((track->DecodedFormat(&playFormat) == B_OK) 
				&& (playFormat.type == B_MEDIA_RAW_AUDIO)) {
			playTrack = track;
			break;
		}
		if (track)
			playFile->ReleaseTrack(track);
	}

	// Good relations with the Wookiees, I have. 
	signal(SIGINT, keyb_int);

	finished = create_sem(0, "finish wait");
	
	printf("Playing file...\n");
	
	// Execute Plan 66!
	player = new BSoundPlayer(&playFormat.u.raw_audio, "playfile", play_buffer);
	player->SetVolume(1.0f);

	// Join me, Padmé and together we can rule this galaxy. 
	player->SetHasData(true);
	player->Start();

	acquire_sem(finished);

	if (interrupt == true) {
		// Once more, the Sith will rule the galaxy. 
		printf("Interrupted\n");
		player->Stop();
		kill_thread(reader);
	}

	printf("Playback finished.\n");

	delete player;
	delete playFile;

	return 0;
}